update queued song #28
36
src/main.rs
36
src/main.rs
@@ -23,8 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// TODO: Do something with the result later
|
||||
// let _ = prep_song(&app_base_url, &song_queue_id).await;
|
||||
match some_work(&app_base_url, &song_queue_id).await {
|
||||
Ok(_) => {
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
}
|
||||
@@ -66,19 +65,27 @@ async fn is_queue_empty(
|
||||
}
|
||||
}
|
||||
|
||||
async fn some_work(app_base_url: &String, song_queue_id: &uuid::Uuid) -> Result<(), std::io::Error> {
|
||||
async fn some_work(
|
||||
app_base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match prep_song(app_base_url, song_queue_id).await {
|
||||
Ok((song_queue_path, coverart_queue_path, metadata)) => {
|
||||
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||
Ok(_applied) => {
|
||||
// let s_path = util::path_buf_to_string(&song_queue_path);
|
||||
match update_queued_song::update_queued_song(app_base_url, &song_queue_path, song_queue_id).await {
|
||||
Ok(_response) => {
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::Other, err.to_string()))
|
||||
}
|
||||
match update_queued_song::update_queued_song(
|
||||
app_base_url,
|
||||
&song_queue_path,
|
||||
song_queue_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_response) => Ok(()),
|
||||
Err(err) => Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
err.to_string(),
|
||||
)),
|
||||
}
|
||||
// Ok((s_path))
|
||||
}
|
||||
@@ -88,13 +95,14 @@ async fn some_work(app_base_url: &String, song_queue_id: &uuid::Uuid) -> Result<
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_err) => {
|
||||
Ok(())
|
||||
}
|
||||
Err(_err) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn prep_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<(String, String, api::get_metadata_queue::response::Metadata), reqwest::Error> {
|
||||
async fn prep_song(
|
||||
api_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<(String, String, api::get_metadata_queue::response::Metadata), reqwest::Error> {
|
||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
||||
Ok(response) => {
|
||||
// Process data here...
|
||||
|
@@ -1,7 +1,5 @@
|
||||
// TODO: Refactor this file when this app is functional
|
||||
|
||||
|
||||
|
||||
// TODO: Create song
|
||||
// TODO: Create coverart
|
||||
// TODO: Wipe data from queued song
|
||||
|
@@ -1,18 +1,23 @@
|
||||
|
||||
use reqwest::multipart;
|
||||
|
||||
// TODO: Update the queued song with the updated queued song
|
||||
pub async fn update_queued_song(base_url: &String, song_path: &String, song_queue_id: &uuid::Uuid) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder()
|
||||
.build()?;
|
||||
pub async fn update_queued_song(
|
||||
base_url: &String,
|
||||
song_path: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
|
||||
let form = reqwest::multipart::Form::new()
|
||||
.part("file",
|
||||
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap()).file_name("track01.flac"));
|
||||
let form = reqwest::multipart::Form::new().part(
|
||||
"file",
|
||||
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap())
|
||||
.file_name("track01.flac"),
|
||||
);
|
||||
|
||||
let method = "PATCH";
|
||||
let url = format!("{}/api/v2/song/queue/{}", base_url, song_queue_id);
|
||||
let request = client.request(reqwest::Method::from_bytes(method.as_bytes()).unwrap(), url)
|
||||
let request = client
|
||||
.request(reqwest::Method::from_bytes(method.as_bytes()).unwrap(), url)
|
||||
.multipart(form);
|
||||
|
||||
let response = request.send().await?;
|
||||
@@ -20,7 +25,6 @@ pub async fn update_queued_song(base_url: &String, song_path: &String, song_queu
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
|
||||
pub fn path_buf_to_string(path: &std::path::PathBuf) -> String {
|
||||
let s_path = match path.to_str() {
|
||||
Some(val) => String::from(val),
|
||||
@@ -7,4 +6,3 @@ pub fn path_buf_to_string(path: &std::path::PathBuf) -> String {
|
||||
|
||||
s_path
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user