Fetch queue item #20
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -1090,7 +1090,10 @@ dependencies = [
|
||||
"dotenvy",
|
||||
"icarus_models",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@@ -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" }
|
||||
|
62
src/main.rs
62
src/main.rs
@@ -1,25 +1,20 @@
|
||||
// use std::error::Error;
|
||||
// use tokio::io::AsyncReadExt;
|
||||
// use tokio::net::{TcpListener, TcpStream};
|
||||
// use tokio::spawn;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
let app_base_url = get_icarus_url().await;
|
||||
|
||||
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::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||
.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
|
||||
@@ -33,6 +28,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// TODO: Create coverart
|
||||
// TODO: Wipe data from queued song
|
||||
// TODO: Wipe data from queued coverart
|
||||
} else {
|
||||
println!("No data to fetch");
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("API call failed: {}", e),
|
||||
}
|
||||
@@ -40,7 +43,36 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Sleeping");
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||
}
|
||||
// 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<QueueItem>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod api {
|
||||
pub async fn fetch_next_queue_item(
|
||||
base_url: &String,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||
let api_url = format!("{}/{}", base_url, fetch_endpoint);
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_icarus_url() -> String {
|
||||
|
Reference in New Issue
Block a user