tsk-203: Addressing hard coding when downloading coverart #223
Generated
+1
-1
@@ -834,7 +834,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
+36
-3
@@ -179,17 +179,50 @@ pub mod endpoint {
|
|||||||
match repo::coverart::get_coverart(&pool, &id).await {
|
match repo::coverart::get_coverart(&pool, &id).await {
|
||||||
Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) {
|
Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
let (file_type, img_type) =
|
||||||
|
match icarus_meta::detection::coverart::file_type_from_data(&data) {
|
||||||
|
Ok(file_type) => {
|
||||||
|
if file_type.file_type
|
||||||
|
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||||
|
{
|
||||||
|
(
|
||||||
|
file_type,
|
||||||
|
icarus_models::types::CoverArtTypes::JpegExtension,
|
||||||
|
)
|
||||||
|
} else if file_type.file_type
|
||||||
|
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||||
|
{
|
||||||
|
(file_type, icarus_models::types::CoverArtTypes::JpgExtension)
|
||||||
|
} else if file_type.file_type
|
||||||
|
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||||
|
{
|
||||||
|
(file_type, icarus_models::types::CoverArtTypes::PngExtension)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::response::Response::default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::response::Response::default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
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();
|
||||||
// TODO: Address hard coding
|
let filename = icarus_models::coverart::generate_filename(img_type, true);
|
||||||
headers.insert(
|
headers.insert(
|
||||||
axum::http::header::CONTENT_TYPE,
|
axum::http::header::CONTENT_TYPE,
|
||||||
"audio/jpg".parse().unwrap(),
|
file_type.mime.parse().unwrap(),
|
||||||
);
|
);
|
||||||
headers.insert(
|
headers.insert(
|
||||||
axum::http::header::CONTENT_DISPOSITION,
|
axum::http::header::CONTENT_DISPOSITION,
|
||||||
format!("attachment; filename=\"{id}.jpg\"")
|
format!("attachment; filename=\"{filename}\"")
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user