This commit is contained in:
@@ -365,45 +365,68 @@ pub mod endpoint {
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
|
||||
Ok(data) => {
|
||||
let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
let bytes = axum::body::Bytes::from(data);
|
||||
let mut response = bytes.into_response();
|
||||
let headers = response.headers_mut();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
file_type.mime.parse().unwrap(),
|
||||
);
|
||||
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 };
|
||||
|
||||
let coverart_type = if file_type.file_type
|
||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||
{
|
||||
simodels::types::CoverArtType::JpegExtension
|
||||
} else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE {
|
||||
simodels::types::CoverArtType::JpgExtension
|
||||
} else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE {
|
||||
simodels::types::CoverArtType::PngExtension
|
||||
} else {
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::response::Response::default(),
|
||||
);
|
||||
};
|
||||
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_DISPOSITION,
|
||||
format!("attachment; filename=\"{filename}\"")
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
match lr.download(&file_key).await {
|
||||
Ok(data) => {
|
||||
let file_type =
|
||||
simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
let bytes = axum::body::Bytes::from(data);
|
||||
let mut response = bytes.into_response();
|
||||
let headers = response.headers_mut();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
file_type.mime.parse().unwrap(),
|
||||
);
|
||||
|
||||
(axum::http::StatusCode::OK, response)
|
||||
let coverart_type = if file_type.file_type
|
||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||
{
|
||||
simodels::types::CoverArtType::JpegExtension
|
||||
} else if file_type.file_type
|
||||
== simeta::detection::coverart::constants::JPG_TYPE
|
||||
{
|
||||
simodels::types::CoverArtType::JpgExtension
|
||||
} else if file_type.file_type
|
||||
== simeta::detection::coverart::constants::PNG_TYPE
|
||||
{
|
||||
simodels::types::CoverArtType::PngExtension
|
||||
} else {
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::response::Response::default(),
|
||||
);
|
||||
};
|
||||
let filename =
|
||||
simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_DISPOSITION,
|
||||
format!("attachment; filename=\"{filename}\"")
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
(axum::http::StatusCode::OK, response)
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::response::Response::default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::response::Response::default(),
|
||||
)
|
||||
}
|
||||
Err(_err) => (
|
||||
axum::http::StatusCode::BAD_REQUEST,
|
||||
axum::response::Response::default(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user