This commit is contained in:
@@ -365,9 +365,15 @@ pub mod endpoint {
|
|||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||||
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
|
match repo::data::queue::coverart::get_with_coverart_queue_id(&pool, &id).await {
|
||||||
|
Ok((_id, file_key, _bucket, _region, _)) => {
|
||||||
|
let lab_config = crate::util::maze::get_config();
|
||||||
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
|
|
||||||
|
match lr.download(&file_key).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
let file_type =
|
||||||
|
simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||||
let bytes = axum::body::Bytes::from(data);
|
let bytes = axum::body::Bytes::from(data);
|
||||||
let mut response = bytes.into_response();
|
let mut response = bytes.into_response();
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
@@ -380,9 +386,13 @@ pub mod endpoint {
|
|||||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||||
{
|
{
|
||||||
simodels::types::CoverArtType::JpegExtension
|
simodels::types::CoverArtType::JpegExtension
|
||||||
} else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE {
|
} else if file_type.file_type
|
||||||
|
== simeta::detection::coverart::constants::JPG_TYPE
|
||||||
|
{
|
||||||
simodels::types::CoverArtType::JpgExtension
|
simodels::types::CoverArtType::JpgExtension
|
||||||
} else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE {
|
} else if file_type.file_type
|
||||||
|
== simeta::detection::coverart::constants::PNG_TYPE
|
||||||
|
{
|
||||||
simodels::types::CoverArtType::PngExtension
|
simodels::types::CoverArtType::PngExtension
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
@@ -390,7 +400,8 @@ pub mod endpoint {
|
|||||||
axum::response::Response::default(),
|
axum::response::Response::default(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
let filename =
|
||||||
|
simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
axum::http::header::CONTENT_DISPOSITION,
|
axum::http::header::CONTENT_DISPOSITION,
|
||||||
format!("attachment; filename=\"{filename}\"")
|
format!("attachment; filename=\"{filename}\"")
|
||||||
@@ -400,10 +411,22 @@ pub mod endpoint {
|
|||||||
|
|
||||||
(axum::http::StatusCode::OK, response)
|
(axum::http::StatusCode::OK, response)
|
||||||
}
|
}
|
||||||
Err(_err) => (
|
Err(err) => {
|
||||||
axum::http::StatusCode::BAD_REQUEST,
|
eprintln!("Error: {err:?}");
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::response::Response::default(),
|
axum::response::Response::default(),
|
||||||
),
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::response::Response::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user