From 47bf24180ba8f7ab10b082b00a7636c811d9c99d Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 19:49:24 +0000 Subject: [PATCH] Wipe data from song queue (#35) Reviewed-on: https://git.kundeng.us/phoenix/songparser/pulls/35 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 32 ++++++++++++++++++++++++++++++++ src/the_rest.rs | 30 ++++++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 6 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" diff --git a/src/main.rs b/src/main.rs index 2cd73d2..226db68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,18 @@ 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 +63,26 @@ 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"); + 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..b5fa85f 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( @@ -76,5 +74,29 @@ pub mod create_coverart { } } -// TODO: Wipe data from queued song -// TODO: Wipe data from queued 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); + + 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 +}