Added code to wipe song queue data

This commit is contained in:
2025-07-15 15:31:37 -04:00
parent c16ad062d4
commit 943d053663
2 changed files with 49 additions and 2 deletions

View File

@@ -31,6 +31,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
(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<dyn std::error::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::<the_rest::wipe_data::song_queue::response::Response>().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> {

View File

@@ -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<reqwest::Response, reqwest::Error> {
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<uuid::Uuid>,
}
}
}
// TODO: Wipe data from queued coverart
}