Code refactoring

This commit is contained in:
2025-10-13 21:47:05 -04:00
parent d55f3b2e46
commit f4972c8caf
2 changed files with 41 additions and 3 deletions

View File

@@ -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<reqwest::Response, reqwest::Error> {
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<uuid::Uuid>,
}
}
}

View File

@@ -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::<update_queued_song::response::Response>()
.json::<api::update_queued_song::response::Response>()
.await
{
Ok(_inner_response) => {