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" diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 82de0ff..fec5fed 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -179,17 +179,50 @@ 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, 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 mut response = bytes.into_response(); let headers = response.headers_mut(); - // TODO: Address hard coding + let filename = icarus_models::coverart::generate_filename(img_type, true); 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=\"{filename}\"") .parse() .unwrap(), );