From b3dca9bd1a8d336377ccaaa56ce78e251e83a1f1 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 10 Jun 2025 18:37:27 -0400 Subject: [PATCH 1/3] Updated crates --- Cargo.lock | 3 +++ Cargo.toml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c0efd87..8be8125 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1090,7 +1090,10 @@ dependencies = [ "dotenvy", "icarus_models", "reqwest", + "serde", + "serde_json", "tokio", + "uuid", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b357dec..6999867 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,9 @@ rust-version = "1.86" [dependencies] tokio = { version = "1.44.1", features = ["full"] } -reqwest = { version = "0.12.19" } +reqwest = { version = "0.12.19", features = ["json"] } +serde = { version = "1.0.218", features = ["derive"] } +serde_json = { version = "1.0.139" } +uuid = { version = "1.16.0", features = ["v4", "serde"] } dotenvy = { version = "0.15.7" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" } -- 2.43.0 From 4c56b48aef2ff04d6ab1d2a619e8b93d47d4f517 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 10 Jun 2025 18:37:55 -0400 Subject: [PATCH 2/3] Able to fetch next song queue item --- src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 68f8219..c1b3f65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ #[tokio::main] async fn main() -> Result<(), Box> { - let client = reqwest::Client::new(); let app_base_url = get_icarus_url().await; loop { @@ -14,12 +13,25 @@ async fn main() -> Result<(), Box> { // TODO: Update the api/v2/song/queue/next endpoint to only retrieve queued song that is // ready to be processed. Make necessary changes to other endpoints - let api_url = format!("{}/api/v2/song/queue/next", app_base_url); + // let api_url = format!("{}/api/v2/song/queue/next", app_base_url); - match client.get(api_url).send().await { + // match client.get(api_url).send().await { + match api::fetch_next_queue_item(&app_base_url).await { Ok(response) => { - let body = response.text().await?; - println!("API response: {}", body); + // let body = response.text().await?; + // println!("API response: {}", body); + match response.json::().await { + Ok(song_queue_item) => { + if !song_queue_item.data.is_empty() { + println!("Song queue item: {:?}", song_queue_item); + } else { + println!("No data to fetch"); + } + } + Err(err) => { + eprintln!("Error: {:?}", err); + } + } // Process data here... // TODO: Parse the response body to a struct @@ -43,6 +55,37 @@ async fn main() -> Result<(), Box> { // Ok(()) } +mod responses { + pub mod fetch_next_queue_item { + use serde::{Deserialize, Serialize}; + + #[derive(Debug, Deserialize, Serialize)] + pub struct QueueItem { + pub id: uuid::Uuid, + pub filename: String, + pub status: String, + } + + #[derive(Debug, Deserialize, Serialize)] + pub struct SongQueueItem { + pub message: String, + pub data: Vec, + } + } +} + +mod api { + pub async fn fetch_next_queue_item(base_url: &String) -> Result { + let client = reqwest::Client::new(); + let fetch_endpoint = String::from("api/v2/song/queue/next"); + let api_url = format!("{}/{}", base_url, fetch_endpoint); + let resp = client.get(api_url).send().await; + + // Ok(resp) + resp + } +} + async fn get_icarus_url() -> String { dotenvy::dotenv().ok(); std::env::var("ICARUS_BASE_API_URL").expect("Could not find url") -- 2.43.0 From 65ce5fee65f562784e347d8c9c5a1bb9e1a08805 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 10 Jun 2025 18:40:04 -0400 Subject: [PATCH 3/3] Code cleanup and formatting --- src/main.rs | 55 +++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1b3f65..8a0e0ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,3 @@ -// use std::error::Error; -// use tokio::io::AsyncReadExt; -// use tokio::net::{TcpListener, TcpStream}; -// use tokio::spawn; - #[tokio::main] async fn main() -> Result<(), Box> { let app_base_url = get_icarus_url().await; @@ -10,20 +5,29 @@ async fn main() -> Result<(), Box> { loop { println!("Base URL: {}", app_base_url); - // TODO: Update the api/v2/song/queue/next endpoint to only retrieve queued song that is - // ready to be processed. Make necessary changes to other endpoints - - // let api_url = format!("{}/api/v2/song/queue/next", app_base_url); - - // match client.get(api_url).send().await { match api::fetch_next_queue_item(&app_base_url).await { Ok(response) => { - // let body = response.text().await?; - // println!("API response: {}", body); - match response.json::().await { + match response + .json::() + .await + { Ok(song_queue_item) => { if !song_queue_item.data.is_empty() { println!("Song queue item: {:?}", song_queue_item); + + // Process data here... + + // TODO: Parse the response body to a struct + // TODO: Get queued song data + // TODO: Get queued song's metadata + // TODO: Get queued coverart + // TODO: Get queued coverart's data + // TODO: Apply metadata to the queued song + // TODO: Update the queued song with the updated queued song + // TODO: Create song + // TODO: Create coverart + // TODO: Wipe data from queued song + // TODO: Wipe data from queued coverart } else { println!("No data to fetch"); } @@ -32,19 +36,6 @@ async fn main() -> Result<(), Box> { eprintln!("Error: {:?}", err); } } - // Process data here... - - // TODO: Parse the response body to a struct - // TODO: Get queued song data - // TODO: Get queued song's metadata - // TODO: Get queued coverart - // TODO: Get queued coverart's data - // TODO: Apply metadata to the queued song - // TODO: Update the queued song with the updated queued song - // TODO: Create song - // TODO: Create coverart - // TODO: Wipe data from queued song - // TODO: Wipe data from queued coverart } Err(e) => eprintln!("API call failed: {}", e), } @@ -52,7 +43,6 @@ async fn main() -> Result<(), Box> { println!("Sleeping"); tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; } - // Ok(()) } mod responses { @@ -75,14 +65,13 @@ mod responses { } mod api { - pub async fn fetch_next_queue_item(base_url: &String) -> Result { + pub async fn fetch_next_queue_item( + base_url: &String, + ) -> Result { let client = reqwest::Client::new(); let fetch_endpoint = String::from("api/v2/song/queue/next"); let api_url = format!("{}/{}", base_url, fetch_endpoint); - let resp = client.get(api_url).send().await; - - // Ok(resp) - resp + client.get(api_url).send().await } } -- 2.43.0