From 943d0536636a13f1f66394d7e230cfad13a9e388 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Jul 2025 15:31:37 -0400 Subject: [PATCH] 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 +}