From ea6f65a20670ec17f16c6a9ba65ee5b4d07b1860 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 15:16:12 -0400 Subject: [PATCH 1/8] icarus_envy version bump --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7e55d6..b973b48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,8 +516,8 @@ dependencies = [ [[package]] name = "icarus_envy" -version = "0.3.2" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd" +version = "0.4.1" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.4.1-main-8f0d123db5-006#8f0d123db51b18e9cc4ab5bd39a474ba99bd39c3" dependencies = [ "const_format", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index 43d6682..3189615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ uuid = { version = "1.17.0", features = ["v4", "serde"] } rand = { version = "0.9.1" } icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" } -icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" } +icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" } -- 2.43.0 From e247870e4da87c3865bfea0a20e8b20ff2a6e8ee Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:21:51 -0400 Subject: [PATCH 2/8] icaurs_models version bump --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9483a7..5f5d47f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -533,8 +533,8 @@ dependencies = [ [[package]] name = "icarus_models" -version = "0.5.6" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.6#2d6b550ae6721b41ecc3039799f6a5e873869077" +version = "0.6.6" +source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.6.6-65-eac7562b80-111#eac7562b80b9f82d21ab737d1e84ba4f12e472dd" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 5079145..f18f263 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,5 @@ time = { version = "0.3.41", features = ["macros", "serde"] } uuid = { version = "1.17.0", features = ["v4", "serde"] } rand = { version = "0.9.1" } icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" } -icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" } +icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.6.6-65-eac7562b80-111" } icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" } -- 2.43.0 From d4e7aba4a8adb8355a2e6e06bf8ba7767ccbba5c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:22:42 -0400 Subject: [PATCH 3/8] Build fix --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 815c343..053a145 100644 --- a/src/main.rs +++ b/src/main.rs @@ -417,7 +417,7 @@ async fn prep_song( // TODO: Consider having something like this in icarus_models pub async fn generate_song_queue_dir_and_filename() -> (String, String) { let mut song = icarus_models::song::Song::default(); - song.filename = song.generate_filename(icarus_models::types::MusicTypes::FlacExtension, true); + song.filename = icarus_models::song::generate_filename(icarus_models::types::MusicTypes::FlacExtension, true); song.directory = icarus_envy::environment::get_root_directory().await.value; -- 2.43.0 From 60069d9e142f10a19375db1d626a68fa83e8176f Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:49:25 -0400 Subject: [PATCH 4/8] code changes --- src/main.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 053a145..7ac8a7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -346,7 +346,29 @@ async fn prep_song( match api::parsing::parse_response_into_bytes(response).await { Ok(song_bytes) => { let (directory, filename) = generate_song_queue_dir_and_filename().await; - let song_queue_path = save_file_to_fs(&directory, &filename, &song_bytes).await; + let song = icarus_models::song::Song { + directory: directory, + filename: filename, + data: song_bytes, + ..Default::default() + }; + let songpath = match song.song_path() { + Ok(songpath) => { + songpath + } + Err(_err) => { + String::new() + } + }; + + let song_queue_path = match song.save_to_filesystem() { + Ok(_) => { + std::path::Path::new(&songpath) + } + Err(_err) => { + std::path::Path::new("") + } + }; println!("Saved at: {song_queue_path:?}"); @@ -376,8 +398,14 @@ async fn prep_song( Ok(response) => match api::parsing::parse_response_into_bytes(response).await { Ok(coverart_queue_bytes) => { let (directory, filename) = generate_coverart_queue_dir_and_filename().await; - let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await; - + let coverart = icarus_models::coverart::CoverArt { + path: directory + "/" + &filename, + data: coverart_queue_bytes, + ..Default::default() + }; + // let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await; + coverart.save_to_filesystem().unwrap(); + let coverart_queue_path = std::path::Path::new(&coverart.path); println!("Saved coverart queue file at: {coverart_queue_path:?}"); let c_path = util::path_buf_to_string(&coverart_queue_path); @@ -454,7 +482,7 @@ pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) { } // TODO: Check to see if this is available in icarus_models -pub async fn save_file_to_fs( +async fn save_file_to_fs( directory: &String, filename: &String, data: &[u8], -- 2.43.0 From cb5cf3a8cabdc2471194f5f4b66895f4ae5ea005 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:56:58 -0400 Subject: [PATCH 5/8] Build changes --- src/main.rs | 72 ++++++++++++++++--------------------------------- src/the_rest.rs | 51 ----------------------------------- 2 files changed, 23 insertions(+), 100 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7ac8a7c..90301de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,6 @@ pub mod the_rest; pub mod update_queued_song; pub mod util; -use std::io::Write; - pub const SECONDS_TO_SLEEP: u64 = 5; #[tokio::main] @@ -64,24 +62,22 @@ async fn main() -> Result<(), Box> { // TODO: Do something with the result later match some_work(&app, &song_queue_id, &user_id).await { Ok(( - _song, - _coverart, - (song_queue_id, song_queue_path), - (coverart_queue_id, coverart_queue_path), + song, + coverart, + (song_queue_id, _song_queue_path), + (coverart_queue_id, _coverart_queue_path), )) => { match wipe_data_from_queues(&app, &song_queue_id, &coverart_queue_id) .await { - Ok(_) => { - match cleanup(&song_queue_path, &coverart_queue_path).await { - Ok(_) => { - println!("Successful cleanup"); - } - Err(err) => { - eprintln!("Error: {err:?}"); - } + Ok(_) => match cleanup(&song, &coverart).await { + Ok(_) => { + println!("Successful cleanup"); } - } + Err(err) => { + eprintln!("Error: {err:?}"); + } + }, Err(err) => { eprintln!("Error: {err:?}"); } @@ -206,17 +202,17 @@ async fn wipe_data_from_queues( } async fn cleanup( - song_queue_path: &String, - coverart_queue_path: &String, + song: &icarus_models::song::Song, + coverart: &icarus_models::coverart::CoverArt, ) -> Result<(), std::io::Error> { - match the_rest::cleanup::clean_song_queue(song_queue_path) { + match song.remove_from_filesystem() { Ok(_) => {} Err(err) => { eprintln!("Error: Problem cleaning up SongQueue files {err:?}"); } } - match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) { + match coverart.remove_from_filesystem() { Ok(_) => Ok(()), Err(err) => Err(err), } @@ -353,21 +349,13 @@ async fn prep_song( ..Default::default() }; let songpath = match song.song_path() { - Ok(songpath) => { - songpath - } - Err(_err) => { - String::new() - } + Ok(songpath) => songpath, + Err(_err) => String::new(), }; let song_queue_path = match song.save_to_filesystem() { - Ok(_) => { - std::path::Path::new(&songpath) - } - Err(_err) => { - std::path::Path::new("") - } + Ok(_) => std::path::Path::new(&songpath), + Err(_err) => std::path::Path::new(""), }; println!("Saved at: {song_queue_path:?}"); @@ -445,7 +433,10 @@ async fn prep_song( // TODO: Consider having something like this in icarus_models pub async fn generate_song_queue_dir_and_filename() -> (String, String) { let mut song = icarus_models::song::Song::default(); - song.filename = icarus_models::song::generate_filename(icarus_models::types::MusicTypes::FlacExtension, true); + song.filename = icarus_models::song::generate_filename( + icarus_models::types::MusicTypes::FlacExtension, + true, + ); song.directory = icarus_envy::environment::get_root_directory().await.value; @@ -481,23 +472,6 @@ pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) { (directory, filename) } -// TODO: Check to see if this is available in icarus_models -async fn save_file_to_fs( - directory: &String, - filename: &String, - data: &[u8], -) -> std::path::PathBuf { - // TODO: Add function to save bytes to a file in icarus_models - // repo - let dir = std::path::Path::new(directory); - let save_path = dir.join(filename); - - let mut file = std::fs::File::create(&save_path).unwrap(); - file.write_all(data).unwrap(); - - save_path -} - pub async fn apply_metadata( song_queue_path: &String, coverart_queue_path: &String, diff --git a/src/the_rest.rs b/src/the_rest.rs index 08aeb4b..5d66e39 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -126,54 +126,3 @@ pub mod wipe_data { } } } - -pub mod cleanup { - pub fn clean_song_queue(song_queue_path: &String) -> Result<(), std::io::Error> { - let file_path = std::path::Path::new(song_queue_path); - if file_path.exists() { - match std::fs::remove_file(file_path) { - Ok(_) => { - if check_file_existence(song_queue_path) { - Err(std::io::Error::other(String::from( - "SongQueue file exists after a deletion", - ))) - } else { - Ok(()) - } - } - Err(err) => Err(std::io::Error::other(err.to_string())), - } - } else { - Err(std::io::Error::other(String::from( - "SongQueue file path does not exists", - ))) - } - } - - pub fn clean_coverart_queue(coverart_queue_path: &String) -> Result<(), std::io::Error> { - let coverart_file_path = std::path::Path::new(coverart_queue_path); - if coverart_file_path.exists() { - match std::fs::remove_file(coverart_file_path) { - Ok(_) => { - if !check_file_existence(coverart_queue_path) { - Ok(()) - } else { - Err(std::io::Error::other(String::from( - "CoverArt file stil exists", - ))) - } - } - Err(err) => Err(std::io::Error::other(err.to_string())), - } - } else { - Err(std::io::Error::other(String::from( - "CoverArt file does not exists", - ))) - } - } - - fn check_file_existence(file_path: &String) -> bool { - let path = std::path::Path::new(file_path); - path.exists() - } -} -- 2.43.0 From 6f348f2101987c29bf4c9b7302f37c04f36e58c0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:58:24 -0400 Subject: [PATCH 6/8] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f5d47f..b3da43f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1320,7 +1320,7 @@ dependencies = [ [[package]] name = "songparser" -version = "0.3.1" +version = "0.3.2" dependencies = [ "futures", "icarus_envy", diff --git a/Cargo.toml b/Cargo.toml index f18f263..2259c0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "songparser" -version = "0.3.1" +version = "0.3.2" edition = "2024" rust-version = "1.88" -- 2.43.0 From dc9e624d494a75a80b3e52e0d4f422ccbef1fc56 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:58:33 -0400 Subject: [PATCH 7/8] Code cleanup --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 90301de..1e25ec4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -391,7 +391,6 @@ async fn prep_song( data: coverart_queue_bytes, ..Default::default() }; - // let coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await; coverart.save_to_filesystem().unwrap(); let coverart_queue_path = std::path::Path::new(&coverart.path); println!("Saved coverart queue file at: {coverart_queue_path:?}"); -- 2.43.0 From d78b131760faec8a5f7e48b49d28460f2ae65ea0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 19:09:49 -0400 Subject: [PATCH 8/8] Cleanup --- src/main.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1e25ec4..88c20d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -343,16 +343,12 @@ async fn prep_song( Ok(song_bytes) => { let (directory, filename) = generate_song_queue_dir_and_filename().await; let song = icarus_models::song::Song { - directory: directory, - filename: filename, + directory, + filename, data: song_bytes, ..Default::default() }; - let songpath = match song.song_path() { - Ok(songpath) => songpath, - Err(_err) => String::new(), - }; - + let songpath = song.song_path().unwrap_or_default(); let song_queue_path = match song.save_to_filesystem() { Ok(_) => std::path::Path::new(&songpath), Err(_err) => std::path::Path::new(""), @@ -395,8 +391,8 @@ async fn prep_song( let coverart_queue_path = std::path::Path::new(&coverart.path); println!("Saved coverart queue file at: {coverart_queue_path:?}"); - let c_path = util::path_buf_to_string(&coverart_queue_path); - let s_path = util::path_buf_to_string(&song_queue_path); + let c_path = util::path_buf_to_string(coverart_queue_path); + let s_path = util::path_buf_to_string(song_queue_path); Ok((s_path, c_path, metadata.clone(), *coverart_queue_id)) } Err(err) => { -- 2.43.0