From 8550af456907a9bd81d07a4e5daa28ed066e2462 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:52:03 -0400 Subject: [PATCH 1/5] tsk-203: Addressing hard coding when downloading coverart --- src/callers/coverart.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 82de0ff..a258570 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -179,17 +179,25 @@ pub mod endpoint { match repo::coverart::get_coverart(&pool, &id).await { Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) { Ok(data) => { + let file_type = match icarus_meta::detection::coverart::file_type_from_data(&data) { + Ok(file_type) => { + file_type + } + Err(err) => { + eprintln!("Error: {err:?}"); + return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::response::Response::default()); + } + }; let bytes = axum::body::Bytes::from(data); let mut response = bytes.into_response(); let headers = response.headers_mut(); - // TODO: Address hard coding headers.insert( axum::http::header::CONTENT_TYPE, - "audio/jpg".parse().unwrap(), + file_type.mime.parse().unwrap() ); headers.insert( axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{id}.jpg\"") + format!("attachment; filename=\"{}\"", coverart.filename) .parse() .unwrap(), ); -- 2.47.3 From 2399d7010d02c17ae78113f837da32689761ca83 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:53:33 -0400 Subject: [PATCH 2/5] tsk-203: Code formatting --- src/callers/coverart.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index a258570..01d23af 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -179,21 +179,23 @@ pub mod endpoint { match repo::coverart::get_coverart(&pool, &id).await { Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) { Ok(data) => { - let file_type = match icarus_meta::detection::coverart::file_type_from_data(&data) { - Ok(file_type) => { - file_type - } - Err(err) => { - eprintln!("Error: {err:?}"); - return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::response::Response::default()); - } - }; + let file_type = + match icarus_meta::detection::coverart::file_type_from_data(&data) { + Ok(file_type) => file_type, + Err(err) => { + eprintln!("Error: {err:?}"); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ); + } + }; 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() + file_type.mime.parse().unwrap(), ); headers.insert( axum::http::header::CONTENT_DISPOSITION, -- 2.47.3 From 8a30ebe6d9e243511f3a24e326a83f49ef27d332 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:53:47 -0400 Subject: [PATCH 3/5] tsk-203: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7fc01e..e81dcfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,7 +834,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.8" +version = "0.3.9" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index b70249a..dcab15f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.8" +version = "0.3.9" edition = "2024" rust-version = "1.90" -- 2.47.3 From 6027d90923e9442858fb5edebd4c987ef099b826 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 14:10:53 -0400 Subject: [PATCH 4/5] tsk-203: Make downloaded coverart file random --- src/callers/coverart.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 01d23af..33a4c48 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -179,9 +179,19 @@ pub mod endpoint { match repo::coverart::get_coverart(&pool, &id).await { Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) { Ok(data) => { - let file_type = + let (file_type, img_type) = match icarus_meta::detection::coverart::file_type_from_data(&data) { - Ok(file_type) => file_type, + 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 ( @@ -193,13 +203,14 @@ pub mod endpoint { let bytes = axum::body::Bytes::from(data); let mut response = bytes.into_response(); let headers = response.headers_mut(); + let filename = icarus_models::coverart::generate_filename(img_type, true); headers.insert( axum::http::header::CONTENT_TYPE, file_type.mime.parse().unwrap(), ); headers.insert( axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{}\"", coverart.filename) + format!("attachment; filename=\"{filename}\"") .parse() .unwrap(), ); -- 2.47.3 From 8cc80b84a8d514eb799374b91adbbee74c9c8087 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 14:11:12 -0400 Subject: [PATCH 5/5] tsk-203: Code formatting --- src/callers/coverart.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 33a4c48..fec5fed 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -182,14 +182,26 @@ pub mod endpoint { 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 { + 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 { + } 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()); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ); } } Err(err) => { -- 2.47.3