diff --git a/Cargo.lock b/Cargo.lock index c47abf5..b83b52e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.14" +version = "0.3.15" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 53c8c25..3c2229f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.14" +version = "0.3.15" edition = "2024" rust-version = "1.90" diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 118e23f..765b1b6 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -69,18 +69,37 @@ pub mod endpoint { match crate::repo::song::get_song(&pool, &song_id).await { Ok(song) => { let directory = icarus_envy::environment::get_root_directory().await.value; - // TODO: Make this random and the file extension should not be hard coded - let filename = format!("{}-coverart.jpeg", &song.filename[..8]); + let file_type = + icarus_meta::detection::coverart::file_type_from_data(&data).unwrap(); + let coverart_type = if file_type.file_type + == icarus_meta::detection::coverart::constants::JPEG_TYPE + { + icarus_models::types::CoverArtType::JpegExtension + } else if file_type.file_type + == icarus_meta::detection::coverart::constants::JPG_TYPE + { + icarus_models::types::CoverArtType::JpgExtension + } else if file_type.file_type + == icarus_meta::detection::coverart::constants::PNG_TYPE + { + icarus_models::types::CoverArtType::PngExtension + } else { + response.message = String::from("Invalid CoverArt type"); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); + }; + let filename = + icarus_models::coverart::generate_filename(coverart_type, true) + .unwrap(); let mut coverart = icarus_models::coverart::init::init_coverart_dir_and_filename( &directory, &filename, ); coverart.title = song.album.clone(); - coverart.file_type = - icarus_meta::detection::coverart::file_type_from_data(&data) - .unwrap() - .file_type; + coverart.file_type = file_type.file_type; coverart.data = data; match coverart.save_to_filesystem() {