From 943d0536636a13f1f66394d7e230cfad13a9e388 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:31:37 -0400 Subject: [PATCH 1/6] Added code to wipe song queue data --- src/main.rs | 25 +++++++++++++++++++++++++ src/the_rest.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2cd73d2..db26eb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,13 @@ async fn main() -> Result<(), Box> { (coverart_queue_id, coverart_queue_path), )) => { // TODO: Wipe data from song and coverart queues + match wipe_data_from_queues(&app_base_url, &song_queue_id, &coverart_queue_id).await { + Ok(_) => { + } + Err(err) => { + eprintln!("Error: {err:?}"); + } + } // TODO: Cleanup files in local filesystem } Err(err) => { @@ -51,6 +58,24 @@ async fn main() -> Result<(), Box> { } } +async fn wipe_data_from_queues(app_base_url: &String, song_queue_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> Result<(), std::io::Error> { + match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await { + Ok(response) => match response.json::().await { + Ok(_resp) => { + println!("Wiped data from song queue"); + println!("Resp: {_resp:?}"); + Ok(()) + } + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } +} + async fn is_queue_empty( api_url: &String, ) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> { diff --git a/src/the_rest.rs b/src/the_rest.rs index 8b12392..64c1c1d 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -76,5 +76,27 @@ pub mod create_coverart { } } -// TODO: Wipe data from queued song -// TODO: Wipe data from queued coverart +pub mod wipe_data { + // TODO: Wipe data from queued song + pub mod song_queue { + pub async fn wipe_data(base_url: &String, song_queue_id: &uuid::Uuid) -> Result { + let client = reqwest::Client::builder().build()?; + let url = format!("{base_url}/api/v2/coverart"); + let payload = serde_json::json!({ + "song_queue_id": song_queue_id + }); + let request = client.post(url).json(&payload); + + request.send().await + } + + pub mod response { + #[derive(Debug, serde::Deserialize, serde::Serialize)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } + } + // TODO: Wipe data from queued coverart +} -- 2.43.0 From dcf4d4ea44dd6050fb302c3774dccc18fc41819c Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:34:48 -0400 Subject: [PATCH 2/6] Changing url --- src/the_rest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/the_rest.rs b/src/the_rest.rs index 64c1c1d..7bde6d2 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -81,7 +81,7 @@ pub mod wipe_data { pub mod song_queue { pub async fn wipe_data(base_url: &String, song_queue_id: &uuid::Uuid) -> Result { let client = reqwest::Client::builder().build()?; - let url = format!("{base_url}/api/v2/coverart"); + let url = format!("{base_url}/api/v2/song/queue/data/wipe"); let payload = serde_json::json!({ "song_queue_id": song_queue_id }); -- 2.43.0 From 47a1c5e8fb45abd193cd3377d62fc30837937a5f Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:38:25 -0400 Subject: [PATCH 3/6] Changed method of request --- src/the_rest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/the_rest.rs b/src/the_rest.rs index 7bde6d2..3dda8e9 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -85,7 +85,7 @@ pub mod wipe_data { let payload = serde_json::json!({ "song_queue_id": song_queue_id }); - let request = client.post(url).json(&payload); + let request = client.patch(url).json(&payload); request.send().await } -- 2.43.0 From 2750fa49d6de718279d205ed42ff613763a05c91 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:40:30 -0400 Subject: [PATCH 4/6] Cleanup --- src/main.rs | 1 - src/the_rest.rs | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index db26eb6..cd890ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,6 @@ async fn wipe_data_from_queues(app_base_url: &String, song_queue_id: &uuid::Uuid Ok(response) => match response.json::().await { Ok(_resp) => { println!("Wiped data from song queue"); - println!("Resp: {_resp:?}"); Ok(()) } Err(err) => { diff --git a/src/the_rest.rs b/src/the_rest.rs index 3dda8e9..d3490fc 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -1,6 +1,5 @@ // TODO: Refactor this file when this app is functional -// TODO: Create song pub mod create_song { pub async fn create( base_url: &String, @@ -44,7 +43,6 @@ pub mod create_song { } } -// TODO: Create coverart pub mod create_coverart { pub async fn create( @@ -77,7 +75,6 @@ pub mod create_coverart { } pub mod wipe_data { - // TODO: Wipe data from queued song pub mod song_queue { pub async fn wipe_data(base_url: &String, song_queue_id: &uuid::Uuid) -> Result { let client = reqwest::Client::builder().build()?; -- 2.43.0 From 3b391067f9b79dc4cca83614e71b929adeed795f Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:40:42 -0400 Subject: [PATCH 5/6] Code formatting --- src/main.rs | 32 ++++++++++++++++++++------------ src/the_rest.rs | 19 +++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index cd890ca..226db68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,9 +31,14 @@ async fn main() -> Result<(), Box> { (coverart_queue_id, coverart_queue_path), )) => { // TODO: Wipe data from song and coverart queues - match wipe_data_from_queues(&app_base_url, &song_queue_id, &coverart_queue_id).await { - Ok(_) => { - } + match wipe_data_from_queues( + &app_base_url, + &song_queue_id, + &coverart_queue_id, + ) + .await + { + Ok(_) => {} Err(err) => { eprintln!("Error: {err:?}"); } @@ -58,20 +63,23 @@ async fn main() -> Result<(), Box> { } } -async fn wipe_data_from_queues(app_base_url: &String, song_queue_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> Result<(), std::io::Error> { +async fn wipe_data_from_queues( + app_base_url: &String, + song_queue_id: &uuid::Uuid, + coverart_queue_id: &uuid::Uuid, +) -> Result<(), std::io::Error> { match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await { - Ok(response) => match response.json::().await { + Ok(response) => match response + .json::() + .await + { Ok(_resp) => { println!("Wiped data from song queue"); Ok(()) } - Err(err) => { - Err(std::io::Error::other(err.to_string())) - } - } - Err(err) => { - Err(std::io::Error::other(err.to_string())) - } + Err(err) => Err(std::io::Error::other(err.to_string())), + }, + Err(err) => Err(std::io::Error::other(err.to_string())), } } diff --git a/src/the_rest.rs b/src/the_rest.rs index d3490fc..b5fa85f 100644 --- a/src/the_rest.rs +++ b/src/the_rest.rs @@ -76,15 +76,18 @@ pub mod create_coverart { pub mod wipe_data { pub mod song_queue { - pub async fn wipe_data(base_url: &String, song_queue_id: &uuid::Uuid) -> Result { - let client = reqwest::Client::builder().build()?; - let url = format!("{base_url}/api/v2/song/queue/data/wipe"); - let payload = serde_json::json!({ - "song_queue_id": song_queue_id - }); - let request = client.patch(url).json(&payload); + pub async fn wipe_data( + base_url: &String, + song_queue_id: &uuid::Uuid, + ) -> Result { + let client = reqwest::Client::builder().build()?; + let url = format!("{base_url}/api/v2/song/queue/data/wipe"); + let payload = serde_json::json!({ + "song_queue_id": song_queue_id + }); + let request = client.patch(url).json(&payload); - request.send().await + request.send().await } pub mod response { -- 2.43.0 From 53cf8876355a9b9bbe711a454a0f68220e67b2e2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:42:19 -0400 Subject: [PATCH 6/6] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68cd5b2..dab90be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "songparser" -version = "0.2.1" +version = "0.2.2" dependencies = [ "futures", "icarus_envy", diff --git a/Cargo.toml b/Cargo.toml index 14cc263..97dae28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "songparser" -version = "0.2.1" +version = "0.2.2" edition = "2024" rust-version = "1.88" -- 2.43.0