From 76619ea61e1eff60a7151513eb1efcb4a9613933 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 13 Jul 2025 19:54:04 -0400 Subject: [PATCH 1/7] Added error checking for file creation in create metadata endpoint --- src/callers/song.rs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index d957ba9..0d53fd0 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -784,26 +784,34 @@ pub mod endpoint { let dir = std::path::Path::new(&song.directory); let save_path = dir.join(&song.filename); - let mut file = std::fs::File::create(&save_path).unwrap(); - file.write_all(&song.data).unwrap(); + // let mut file = std::fs::File::create(&save_path).unwrap(); + 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.data.push(song); + 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.data.push(song); - (axum::http::StatusCode::OK, 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::BAD_REQUEST, 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)) + (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) } } } -- 2.47.3 From 2c0e3d290cd0a09eb602c97c7d5834f5ff1bdda4 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 13 Jul 2025 19:55:11 -0400 Subject: [PATCH 2/7] Code formatting --- src/callers/song.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index 0d53fd0..18fb05e 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -799,7 +799,8 @@ pub mod endpoint { (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { - response.message = format!("{:?} song {:?}", err.to_string(), song); + response.message = + format!("{:?} song {:?}", err.to_string(), song); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } }, @@ -811,7 +812,10 @@ pub mod endpoint { } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } } -- 2.47.3 From f5402d0f14b8e1c727c1ecd0e27cb38f84bc05e9 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 14 Jul 2025 19:32:04 -0400 Subject: [PATCH 3/7] Fixed create metadata endoint --- src/callers/song.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index 18fb05e..6a2ac02 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -782,6 +782,17 @@ pub mod endpoint { Ok(data) => { song.data = data; let dir = std::path::Path::new(&song.directory); + if !dir.exists() { + println!("Creating directory"); + match std::fs::create_dir_all(&dir) { + Ok(_) => { + println!("Successfully created directory"); + } + Err(err) => { + eprintln!("Error: Unable to create the directory {err:?}"); + } + } + } let save_path = dir.join(&song.filename); // let mut file = std::fs::File::create(&save_path).unwrap(); @@ -811,7 +822,8 @@ pub mod endpoint { } } Err(err) => { - response.message = err.to_string(); + let song_path = song.song_path(); + response.message = format!("{} Song directory: {} Filename: {} Save Path: {:?} Song Path: {:?}", err.to_string(), song.directory, song.filename, save_path, song_path); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), -- 2.47.3 From 41efb1fb1594ee6da4f7121491e7b46417f49687 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 14 Jul 2025 19:33:58 -0400 Subject: [PATCH 4/7] Added missing message in the response --- src/callers/song.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/callers/song.rs b/src/callers/song.rs index 6a2ac02..c88180e 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -805,6 +805,7 @@ pub mod endpoint { 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)) -- 2.47.3 From 9b1c0b718f2b1b05fcb8297adb49ae6ccae16849 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 14 Jul 2025 19:35:34 -0400 Subject: [PATCH 5/7] Cleanup --- src/callers/song.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index c88180e..a06cabb 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -793,9 +793,9 @@ pub mod endpoint { } } } + let save_path = dir.join(&song.filename); - // let mut file = std::fs::File::create(&save_path).unwrap(); match std::fs::File::create(&save_path) { Ok(mut file) => { file.write_all(&song.data).unwrap(); -- 2.47.3 From 68686d4a305e853606be621b6383fab9cc23df3e Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 14 Jul 2025 19:37:05 -0400 Subject: [PATCH 6/7] Warning fixes --- src/callers/song.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index a06cabb..bf17ca9 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -784,7 +784,7 @@ pub mod endpoint { let dir = std::path::Path::new(&song.directory); if !dir.exists() { println!("Creating directory"); - match std::fs::create_dir_all(&dir) { + match std::fs::create_dir_all(dir) { Ok(_) => { println!("Successfully created directory"); } @@ -824,7 +824,7 @@ pub mod endpoint { } Err(err) => { let song_path = song.song_path(); - response.message = format!("{} Song directory: {} Filename: {} Save Path: {:?} Song Path: {:?}", err.to_string(), song.directory, song.filename, save_path, 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), -- 2.47.3 From 71c6ed4dbf337aae1099503818261678dfa3254e Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 14 Jul 2025 19:37:21 -0400 Subject: [PATCH 7/7] Code formatting --- src/callers/song.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index bf17ca9..f8ee210 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -824,7 +824,10 @@ pub mod endpoint { } 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); + 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), -- 2.47.3