Code refactoring
This commit is contained in:
39
src/api.rs
39
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<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>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -2,7 +2,6 @@ pub mod api;
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod responses;
|
pub mod responses;
|
||||||
pub mod the_rest;
|
pub mod the_rest;
|
||||||
pub mod update_queued_song;
|
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
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 {
|
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match update_queued_song::update_queued_song(
|
match api::update_queued_song::update_queued_song(
|
||||||
app,
|
app,
|
||||||
&song_queue_path,
|
&song_queue_path,
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
@@ -271,7 +270,7 @@ async fn some_work(
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<update_queued_song::response::Response>()
|
.json::<api::update_queued_song::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_inner_response) => {
|
Ok(_inner_response) => {
|
||||||
|
Reference in New Issue
Block a user