tsk-202: Make downloaded CoverArt filename random

This commit is contained in:
kdeng00
2025-10-30 16:32:13 -04:00
parent fd4e661b3c
commit 9f3e49bd01
+22 -5
View File
@@ -69,18 +69,35 @@ pub mod endpoint {
match crate::repo::song::get_song(&pool, &song_id).await { match crate::repo::song::get_song(&pool, &song_id).await {
Ok(song) => { Ok(song) => {
let directory = icarus_envy::environment::get_root_directory().await.value; let directory = icarus_envy::environment::get_root_directory().await.value;
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)
);
};
// TODO: Make this random and the file extension should not be hard coded // TODO: Make this random and the file extension should not be hard coded
let filename = format!("{}-coverart.jpeg", &song.filename[..8]); let filename = icarus_models::coverart::generate_filename(coverart_type, true).unwrap();
let mut coverart = let mut coverart =
icarus_models::coverart::init::init_coverart_dir_and_filename( icarus_models::coverart::init::init_coverart_dir_and_filename(
&directory, &filename, &directory, &filename,
); );
coverart.title = song.album.clone(); coverart.title = song.album.clone();
coverart.file_type = coverart.file_type = file_type.file_type;
icarus_meta::detection::coverart::file_type_from_data(&data)
.unwrap()
.file_type;
coverart.data = data; coverart.data = data;
match coverart.save_to_filesystem() { match coverart.save_to_filesystem() {