From 1bf0ed7e190fdbe3d0e54749a14f770683069be4 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:36:19 -0400 Subject: [PATCH 1/7] tsk-213: Adding song check when queueing songs --- src/callers/queue/song.rs | 48 +++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 73c09c7..6c1fbd5 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -96,6 +96,21 @@ pub mod response { } } +pub async fn is_song_valid(data: &[u8]) -> Result { + match icarus_meta::detection::song::file_type_from_data(data) { + Ok(file_type) => { + if file_type.file_type == icarus_meta::detection::song::constants::FLAC_TYPE { + Ok(true) + } else { + Ok(false) + } + } + Err(err) => { + Err(err) + } + } +} + pub mod endpoint { use axum::response::IntoResponse; @@ -139,22 +154,35 @@ pub mod endpoint { ); let raw_data: Vec = data.to_vec(); - let queue_repo = repo::song::insert( - &pool, - &raw_data, - &file_name, - &crate::repo::queue::song::status::PENDING.to_string(), - ) - .await - .unwrap(); - results.push(queue_repo); + match super::is_song_valid(&raw_data).await { + Ok(valid) => { + if valid { + let queue_repo = repo::song::insert( + &pool, + &raw_data, + &file_name, + &crate::repo::queue::song::status::PENDING.to_string(), + ) + .await + .unwrap(); + results.push(queue_repo); + } else { + response.message = String::from("Invalid song type"); + return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + } + } + Err(err) => { + response.message = err.to_string(); + return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)); + } + } } response.data = results; response.message = if response.data.is_empty() { String::from("Error") } else { - String::from("Success") + String::from(super::super::super::response::SUCCESSFUL) }; (axum::http::StatusCode::OK, axum::Json(response)) -- 2.47.3 From e0d6cbcbf5d146dd491b95d57cab08b2d3c03a67 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:41:31 -0400 Subject: [PATCH 2/7] tsk-213: Added check for updating queued song --- src/callers/queue/song.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 6c1fbd5..097081a 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -411,15 +411,28 @@ pub mod endpoint { ); let raw_data: Vec = data.to_vec(); - match repo::song::update(&pool, &raw_data, &id).await { - Ok(_) => { - response.message = String::from("Successful"); - response.data.push(id); - (axum::http::StatusCode::OK, axum::Json(response)) + match super::is_song_valid(&raw_data).await { + Ok(valid) => { + if valid { + match repo::song::update(&pool, &raw_data, &id).await { + Ok(_) => { + response.message = String::from(super::super::super::response::SUCCESSFUL); + response.data.push(id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } else { + response.message = String::from("Invalid song type"); + return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + } } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)); } } } else { -- 2.47.3 From 1d127e08275772d8bda7af411b37cf162a7cef6d Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:42:14 -0400 Subject: [PATCH 3/7] tsk-213: Removed todo --- src/callers/queue/song.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 097081a..da90870 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -262,7 +262,6 @@ pub mod endpoint { } } - // TODO: Rename /// Endpoint to download the queued song #[utoipa::path( get, -- 2.47.3 From 8cc3d64d42cae40b322926f1ba36864c18a64b7c Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:42:27 -0400 Subject: [PATCH 4/7] tsk-213: Code cleanup --- src/callers/queue/song.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index da90870..1a1c664 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -105,9 +105,7 @@ pub async fn is_song_valid(data: &[u8]) -> Result { Ok(false) } } - Err(err) => { - Err(err) - } + Err(err) => Err(err), } } @@ -168,12 +166,18 @@ pub mod endpoint { results.push(queue_repo); } else { response.message = String::from("Invalid song type"); - return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); } } Err(err) => { response.message = err.to_string(); - return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); } } } @@ -415,7 +419,8 @@ pub mod endpoint { if valid { match repo::song::update(&pool, &raw_data, &id).await { Ok(_) => { - response.message = String::from(super::super::super::response::SUCCESSFUL); + response.message = + String::from(super::super::super::response::SUCCESSFUL); response.data.push(id); (axum::http::StatusCode::OK, axum::Json(response)) } @@ -426,12 +431,18 @@ pub mod endpoint { } } else { response.message = String::from("Invalid song type"); - return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); } } Err(err) => { response.message = err.to_string(); - return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); } } } else { -- 2.47.3 From 7aead9399cfcfc4c706adf81cd670711bfaec687 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:43:40 -0400 Subject: [PATCH 5/7] tsk-213: Warning fix --- src/callers/queue/song.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 1a1c664..9e6ba8b 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -431,18 +431,18 @@ pub mod endpoint { } } else { response.message = String::from("Invalid song type"); - return ( + ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), - ); + ) } } Err(err) => { response.message = err.to_string(); - return ( + ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), - ); + ) } } } else { -- 2.47.3 From 186956fc46c90f9fb6a7615b8f4436e9a2751227 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:43:50 -0400 Subject: [PATCH 6/7] tsk-213: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e81dcfb..ee7173a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,7 +834,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.9" +version = "0.3.10" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index dcab15f..55321cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.9" +version = "0.3.10" edition = "2024" rust-version = "1.90" -- 2.47.3 From d718e0017c9db2ee43a6be3a6a41f4bc6c3c7850 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 29 Oct 2025 14:53:59 -0400 Subject: [PATCH 7/7] tsk-213: Minor status code changes --- src/callers/queue/song.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 9e6ba8b..1dcf38d 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -166,10 +166,7 @@ pub mod endpoint { results.push(queue_repo); } else { response.message = String::from("Invalid song type"); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::Json(response), - ); + return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)); } } Err(err) => { @@ -426,15 +423,15 @@ pub mod endpoint { } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } } else { response.message = String::from("Invalid song type"); - ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::Json(response), - ) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } Err(err) => { -- 2.47.3