This commit is contained in:
kdeng00
2025-10-11 19:45:41 -04:00
parent 0b636d5557
commit a4ca9e212a
2 changed files with 33 additions and 70 deletions
+20 -14
View File
@@ -473,8 +473,6 @@ pub mod cov_db {
} }
pub mod endpoint { pub mod endpoint {
use std::io::Write;
use axum::response::IntoResponse; use axum::response::IntoResponse;
/// Endpoint to queue cover art /// Endpoint to queue cover art
@@ -714,23 +712,31 @@ pub mod endpoint {
coverart.title = song.album.clone(); coverart.title = song.album.clone();
coverart.data = data; coverart.data = data;
let mut file = std::fs::File::create(&save_path).unwrap(); match coverart.save_to_filesystem() {
file.write_all(&coverart.data).unwrap(); 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 { response.message = String::from("Successful");
Ok(id) => { response.data.push(coverart);
// TODO: Populate song_id
coverart.id = id;
println!("Cover Art created");
response.message = String::from("Successful"); (axum::http::StatusCode::OK, axum::Json(response))
response.data.push(coverart); }
Err(err) => {
(axum::http::StatusCode::OK, axum::Json(response)) response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
} }
} }
} }
+13 -56
View File
@@ -1230,71 +1230,28 @@ pub mod endpoint {
} }
match song.save_to_filesystem() { match song.save_to_filesystem() {
Ok(_) => { Ok(_) => match super::song_db::insert(&pool, &song).await {
match super::song_db::insert(&pool, &song).await { Ok((date_created, id)) => {
Ok((date_created, id)) => { song.id = id;
song.id = id; song.date_created = date_created;
song.date_created = date_created; response.message = String::from("Successful");
response.message = String::from("Successful"); response.data.push(song);
response.data.push(song);
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
} }
Err(err) => { Err(err) => {
response.message = response.message = format!("{:?} song {:?}", err.to_string(), song);
format!("{:?} song {:?}", err.to_string(), song); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) }
} },
}
}
Err(err) => { Err(err) => {
response.message = err.to_string(); 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::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response), axum::Json(response),
) )
} }
} }
*/
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); response.message = err.to_string();