From f4972c8caf9d417c8eb2a66f7821eb0c5d396ea0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 13 Oct 2025 21:47:05 -0400 Subject: [PATCH] Code refactoring --- src/api.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/main.rs | 5 ++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/api.rs b/src/api.rs index ff23283..3673a36 100644 --- a/src/api.rs +++ b/src/api.rs @@ -167,3 +167,42 @@ pub mod refresh_token { } } } + +pub mod update_queued_song { + pub async fn update_queued_song( + app: &crate::config::App, + song_path: &String, + song_queue_id: &uuid::Uuid, + ) -> Result { + let client = reqwest::Client::builder().build()?; + + println!("Song path: {song_path:?}"); + + // TODO: Make the filename random + let form = reqwest::multipart::Form::new().part( + "file", + reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap()) + .file_name("track01.flac"), + ); + + let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri); + println!("Url: {url:?}"); + + let (key, header) = crate::api::auth_header(app).await; + let request = client.patch(url).multipart(form).header(key, header); + + let response = request.send().await?; + + Ok(response) + } + + pub mod response { + use serde::{Deserialize, Serialize}; + + #[derive(Debug, Deserialize, Serialize)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } +} diff --git a/src/main.rs b/src/main.rs index cbb3199..f898af4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ pub mod api; pub mod config; pub mod responses; pub mod the_rest; -pub mod update_queued_song; pub mod util; pub const SECONDS_TO_SLEEP: u64 = 5; @@ -262,7 +261,7 @@ async fn some_work( match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await { Ok(_applied) => { - match update_queued_song::update_queued_song( + match api::update_queued_song::update_queued_song( app, &song_queue_path, song_queue_id, @@ -271,7 +270,7 @@ async fn some_work( { Ok(response) => { match response - .json::() + .json::() .await { Ok(_inner_response) => {