From c046bf270aeb4e884afc7759627dc3ea3ee841fe Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 11:50:14 -0400 Subject: [PATCH 01/11] tsk-212: icarus_meta version bump --- Cargo.lock | 12 ++++++++++-- Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 779eec5..7b6c959 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,10 +864,12 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.0" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.0#f372d059155691c0bac52594fa0d14867078e461" +version = "0.4.1" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.1-main-5101f36aed-680#5101f36aed96e9c8475286ee6b9c993d65105779" dependencies = [ + "imghdr", "lofty", + "rand 0.9.2", ] [[package]] @@ -991,6 +993,12 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "imghdr" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8b35f3ad95576ac81603375dfe47a0450b70a368aa34d2b6e5bb0a0d7f02428" + [[package]] name = "indexmap" version = "2.12.0" diff --git a/Cargo.toml b/Cargo.toml index ebf0655..cec4493 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ jsonwebtoken = { version = "9.3.1" } josekit = { version = "0.10.3" } utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.0" } +icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.1-main-5101f36aed-680" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" } -- 2.47.3 From 3f0fedc7ea70a2e83bfd75ebe3a74d718d695319 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 12:21:19 -0400 Subject: [PATCH 02/11] tsk-212: icarus_meta version bump --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b6c959..973e02a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,8 +864,8 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.1" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.1-main-5101f36aed-680#5101f36aed96e9c8475286ee6b9c993d65105779" +version = "0.4.2" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.2-main-71374eb731-680#71374eb73180966d11a7298df06fdc6e999c3c78" dependencies = [ "imghdr", "lofty", diff --git a/Cargo.toml b/Cargo.toml index cec4493..cd7105d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ jsonwebtoken = { version = "9.3.1" } josekit = { version = "0.10.3" } utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.1-main-5101f36aed-680" } +icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.2-main-71374eb731-680" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" } -- 2.47.3 From 5cf37cee6a1552a9eaa054abc93965739d30621f Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 12:45:08 -0400 Subject: [PATCH 03/11] tsk-212: Got functionality working --- src/callers/coverart.rs | 71 +++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 09901cb..c6c60f1 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -485,6 +485,24 @@ pub mod cov_db { } } +mod helper { + pub fn is_coverart_file_type_valid(file_type: &String) -> bool { + let valid_file_types = vec![ + String::from("png"), + String::from("jpg"), + String::from("jpeg"), + ]; + + for valid_file_type in valid_file_types { + if valid_file_type == *file_type { + return true; + } + } + + return false; + } +} + pub mod endpoint { use axum::response::IntoResponse; @@ -516,24 +534,45 @@ pub mod endpoint { let content_type = field.content_type().unwrap().to_string(); let data = field.bytes().await.unwrap(); let raw_data = data.to_vec(); + let file_type = + match icarus_meta::detection::coverart::file_type_from_data(&raw_data) { + Ok(file_type) => file_type, + Err(err) => { + eprintln!("Error: {err:?}"); + response.message = err.to_string(); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); + } + }; - println!( - "Received file '{}' (name = '{}', content-type = '{}', size = {})", - file_name, - name, - content_type, - data.len() - ); + if !super::helper::is_coverart_file_type_valid(&file_type) { + response.message = format!("CoverArt file type not supported: {file_type:?}"); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); + } else { + println!( + "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {})", + file_name, + name, + content_type, + data.len(), + file_type + ); - match super::db::insert(&pool, &raw_data).await { - Ok(id) => { - response.message = String::from("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)) + match super::db::insert(&pool, &raw_data).await { + Ok(id) => { + response.message = String::from("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)) + } } } } -- 2.47.3 From 5244c4e8e54838c578c944ec149f7dca30e450cf Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 12:57:17 -0400 Subject: [PATCH 04/11] tsk-212: Migration changes Added file_type to CoverArtQueue --- migrations/20250420185217_init_migration.sql | 1 + test_migrations/20250725213944_init.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/migrations/20250420185217_init_migration.sql b/migrations/20250420185217_init_migration.sql index 621a949..0083b57 100644 --- a/migrations/20250420185217_init_migration.sql +++ b/migrations/20250420185217_init_migration.sql @@ -22,6 +22,7 @@ CREATE TABLE IF NOT EXISTS "metadataQueue" ( CREATE TABLE IF NOT EXISTS "coverartQueue" ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), data BYTEA NULL, + file_type TEXT NOT NULL, song_queue_id UUID NULL ); diff --git a/test_migrations/20250725213944_init.sql b/test_migrations/20250725213944_init.sql index 267ee8b..d186f00 100644 --- a/test_migrations/20250725213944_init.sql +++ b/test_migrations/20250725213944_init.sql @@ -22,6 +22,7 @@ CREATE TABLE IF NOT EXISTS "metadataQueue" ( CREATE TABLE IF NOT EXISTS "coverartQueue" ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), data BYTEA NULL, + file_type TEXT NOT NULL, song_queue_id UUID NULL ); -- 2.47.3 From 18b64022cf7eaff4b64c4e841bbef887a61faea6 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 12:58:03 -0400 Subject: [PATCH 05/11] tsk-212: Add support to save file_type from CoverArtQueue --- src/callers/coverart.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index c6c60f1..699051a 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -2,6 +2,7 @@ #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct CoverArtQueue { pub id: uuid::Uuid, + pub file_type: String, pub song_queue_id: uuid::Uuid, } @@ -131,13 +132,18 @@ pub mod response { pub mod db { use sqlx::Row; - pub async fn insert(pool: &sqlx::PgPool, data: &Vec) -> Result { + pub async fn insert( + pool: &sqlx::PgPool, + data: &Vec, + file_type: &str, + ) -> Result { let result = sqlx::query( r#" - INSERT INTO "coverartQueue" (data) VALUES($1) RETURNING id; + INSERT INTO "coverartQueue" (data, file_type) VALUES($1, $2) RETURNING id; "#, ) .bind(data) + .bind(file_type) .fetch_one(pool) .await .map_err(|e| { @@ -183,7 +189,7 @@ pub mod db { ) -> Result { let result = sqlx::query( r#" - SELECT id, song_queue_id FROM "coverartQueue" WHERE id = $1; + SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE id = $1; "#, ) .bind(id) @@ -199,6 +205,10 @@ pub mod db { .try_get("id") .map_err(|_e| sqlx::Error::RowNotFound) .unwrap(), + file_type: row + .try_get("file_type") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap(), song_queue_id: row .try_get("song_queue_id") .map_err(|_e| sqlx::Error::RowNotFound) @@ -214,7 +224,7 @@ pub mod db { ) -> Result { let result = sqlx::query( r#" - SELECT id, song_queue_id FROM "coverartQueue" WHERE song_queue_id = $1; + SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE song_queue_id = $1; "#, ) .bind(song_queue_id) @@ -230,6 +240,10 @@ pub mod db { .try_get("id") .map_err(|_e| sqlx::Error::RowNotFound) .unwrap(), + file_type: row + .try_get("file_type") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap(), song_queue_id: row .try_get("song_queue_id") .map_err(|_e| sqlx::Error::RowNotFound) @@ -563,7 +577,7 @@ pub mod endpoint { file_type ); - match super::db::insert(&pool, &raw_data).await { + match super::db::insert(&pool, &raw_data, &file_type).await { Ok(id) => { response.message = String::from("Successful"); response.data.push(id); -- 2.47.3 From 3742d792ba580612865186177e18733d58ba1a32 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 13:23:19 -0400 Subject: [PATCH 06/11] tsk-212: Warning fix --- src/callers/coverart.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 699051a..0b84ee9 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -513,7 +513,7 @@ mod helper { } } - return false; + false } } @@ -563,10 +563,10 @@ pub mod endpoint { if !super::helper::is_coverart_file_type_valid(&file_type) { response.message = format!("CoverArt file type not supported: {file_type:?}"); - return ( + ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), - ); + ) } else { println!( "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {})", -- 2.47.3 From 6b91413227ad34bd3c8cf6fd384c8d9575ffd2df Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 19:41:55 -0400 Subject: [PATCH 07/11] tsk-212: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 973e02a..e9a4091 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -823,7 +823,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.1" +version = "0.3.2" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index cd7105d..ab68716 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.1" +version = "0.3.2" edition = "2024" rust-version = "1.90" -- 2.47.3 From 90eeeb920ca42a938bec38765abf00023bac88d6 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 21:41:23 -0400 Subject: [PATCH 08/11] tsk-212: icarus_meta version bump --- Cargo.lock | 25 +++++++++++++++++++++++-- Cargo.toml | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9a4091..c7f8059 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,6 +193,17 @@ dependencies = [ "shlex", ] +[[package]] +name = "cfb" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" +dependencies = [ + "byteorder", + "fnv", + "uuid", +] + [[package]] name = "cfg-if" version = "1.0.4" @@ -864,10 +875,11 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.2" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.2-main-71374eb731-680#71374eb73180966d11a7298df06fdc6e999c3c78" +version = "0.4.3" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.3-48-561d740120-680#561d740120d9d2e0224bff0c8a4d7d40c6230413" dependencies = [ "imghdr", + "infer", "lofty", "rand 0.9.2", ] @@ -1011,6 +1023,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "infer" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a588916bfdfd92e71cacef98a63d9b1f0d74d6599980d11894290e7ddefffcf7" +dependencies = [ + "cfb", +] + [[package]] name = "itoa" version = "1.0.15" diff --git a/Cargo.toml b/Cargo.toml index ab68716..b7f0c5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ jsonwebtoken = { version = "9.3.1" } josekit = { version = "0.10.3" } utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.2-main-71374eb731-680" } +icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.3-48-561d740120-680" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" } -- 2.47.3 From 3bb739ed20033c3d772a8fadf948a1b8b3d9a253 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 22:03:19 -0400 Subject: [PATCH 09/11] tsk-212: icarus_meta version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7f8059..61184e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -876,7 +876,7 @@ dependencies = [ [[package]] name = "icarus_meta" version = "0.4.3" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.3-48-561d740120-680#561d740120d9d2e0224bff0c8a4d7d40c6230413" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.4.3-48-8acf220fc4-680#8acf220fc4a646090cfb54eff78aaa2f172bf882" dependencies = [ "imghdr", "infer", diff --git a/Cargo.toml b/Cargo.toml index b7f0c5e..2cc9f7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ jsonwebtoken = { version = "9.3.1" } josekit = { version = "0.10.3" } utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.3-48-561d740120-680" } +icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.3-48-8acf220fc4-680" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" } -- 2.47.3 From aa0173c179615a16ae0d06725031b81e3aa69196 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 22:03:50 -0400 Subject: [PATCH 10/11] tsk-212: icarus_meta related changes --- src/callers/coverart.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 0b84ee9..c8acde3 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -561,7 +561,7 @@ pub mod endpoint { } }; - if !super::helper::is_coverart_file_type_valid(&file_type) { + if !super::helper::is_coverart_file_type_valid(&file_type.file_type) { response.message = format!("CoverArt file type not supported: {file_type:?}"); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, @@ -569,7 +569,7 @@ pub mod endpoint { ) } else { println!( - "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {})", + "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {:?})", file_name, name, content_type, @@ -577,7 +577,7 @@ pub mod endpoint { file_type ); - match super::db::insert(&pool, &raw_data, &file_type).await { + match super::db::insert(&pool, &raw_data, &file_type.file_type).await { Ok(id) => { response.message = String::from("Successful"); response.data.push(id); -- 2.47.3 From bd6027f9fb4ce1c91658f1fd845cf37fabb741d4 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 21 Oct 2025 22:19:51 -0400 Subject: [PATCH 11/11] tsk-212: Replaced code with constants --- src/callers/coverart.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index c8acde3..0c68afe 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -502,9 +502,9 @@ pub mod cov_db { mod helper { pub fn is_coverart_file_type_valid(file_type: &String) -> bool { let valid_file_types = vec![ - String::from("png"), - String::from("jpg"), - String::from("jpeg"), + String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE), + String::from(icarus_meta::detection::coverart::constants::JPG_TYPE), + String::from(icarus_meta::detection::coverart::constants::PNG_TYPE), ]; for valid_file_type in valid_file_types { -- 2.47.3