From a4ca9e212a66647a5d4acfacfe876bbaac2ee08b Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 11 Oct 2025 19:45:41 -0400 Subject: [PATCH] Changes --- src/callers/coverart.rs | 34 +++++++++++--------- src/callers/song.rs | 69 ++++++++--------------------------------- 2 files changed, 33 insertions(+), 70 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 797be80..90be44e 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -473,8 +473,6 @@ pub mod cov_db { } pub mod endpoint { - use std::io::Write; - use axum::response::IntoResponse; /// Endpoint to queue cover art @@ -714,23 +712,31 @@ pub mod endpoint { coverart.title = song.album.clone(); coverart.data = data; - let mut file = std::fs::File::create(&save_path).unwrap(); - file.write_all(&coverart.data).unwrap(); + match coverart.save_to_filesystem() { + Ok(_) => { + match super::cov_db::create(&pool, &coverart, &song.id).await { + Ok(id) => { + // TODO: Populate song_id + coverart.id = id; + println!("Cover Art created"); - match super::cov_db::create(&pool, &coverart, &song.id).await { - Ok(id) => { - // TODO: Populate song_id - coverart.id = id; - println!("Cover Art created"); + response.message = String::from("Successful"); + response.data.push(coverart); - response.message = String::from("Successful"); - response.data.push(coverart); - - (axum::http::StatusCode::OK, axum::Json(response)) + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } } diff --git a/src/callers/song.rs b/src/callers/song.rs index d3e3dfc..485626e 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -1230,71 +1230,28 @@ pub mod endpoint { } match song.save_to_filesystem() { - Ok(_) => { - match super::song_db::insert(&pool, &song).await { - Ok((date_created, id)) => { - song.id = id; - song.date_created = date_created; - response.message = String::from("Successful"); - response.data.push(song); + Ok(_) => match super::song_db::insert(&pool, &song).await { + Ok((date_created, id)) => { + song.id = id; + song.date_created = date_created; + response.message = String::from("Successful"); + response.data.push(song); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = - format!("{:?} song {:?}", err.to_string(), song); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = format!("{:?} song {:?}", err.to_string(), song); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + }, Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) - } - } - - // let save_path = dir.join(&song.filename); - - /* - match std::fs::File::create(&save_path) { - Ok(mut file) => { - file.write_all(&song.data).unwrap(); - - match song.song_path() { - Ok(_) => match super::song_db::insert(&pool, &song).await { - Ok((date_created, id)) => { - song.id = id; - song.date_created = date_created; - response.message = String::from("Successful"); - response.data.push(song); - - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = - format!("{:?} song {:?}", err.to_string(), song); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - }, - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - Err(err) => { - let song_path = song.song_path(); - response.message = format!( - "{err:?} Song directory: {} Filename: {} Save Path: {:?} Song Path: {:?}", - song.directory, song.filename, save_path, song_path - ); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), ) } } - */ } Err(err) => { response.message = err.to_string();