Get queued coverart data #26

Merged
phoenix merged 7 commits from queued_coverart_data into devel 2025-06-19 00:54:14 +00:00
Showing only changes of commit 578e7e2d99 - Show all commits

View File

@@ -59,10 +59,10 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
Ok(response) => {
// Process data here...
match api::fetch_song_queue_data::response::parse_response(response).await {
Ok(all_bytes) => {
match api::parsing::parse_response_into_bytes(response).await {
Ok(song_bytes) => {
let (directory, filename) = generate_song_queue_dir_and_filename().await;
let save_path = save_song_to_fs(&directory, &filename, &all_bytes).await;
let save_path = save_song_to_fs(&directory, &filename, &song_bytes).await;
println!("Saved at: {:?}", save_path);
@@ -182,6 +182,26 @@ mod api {
client.get(api_url).send().await
}
pub mod parsing {
use futures::StreamExt;
pub async fn parse_response_into_bytes(
response: reqwest::Response,
) -> Result<Vec<u8>, reqwest::Error> {
// TODO: At some point, handle the flow if the size is small or
// large
let mut byte_stream = response.bytes_stream();
let mut all_bytes = Vec::new();
while let Some(chunk) = byte_stream.next().await {
let chunk = chunk?;
all_bytes.extend_from_slice(&chunk);
}
Ok(all_bytes)
}
}
pub mod fetch_song_queue_data {
pub async fn get_data(
base_url: &String,
@@ -192,26 +212,6 @@ mod api {
let api_url = format!("{}/{}/{}", base_url, endpoint, id);
client.get(api_url).send().await
}
pub mod response {
use futures::StreamExt;
pub async fn parse_response(
response: reqwest::Response,
) -> Result<Vec<u8>, reqwest::Error> {
// TODO: At some point, handle the flow if the size is small or
// large
let mut byte_stream = response.bytes_stream();
let mut all_bytes = Vec::new();
while let Some(chunk) = byte_stream.next().await {
let chunk = chunk?;
all_bytes.extend_from_slice(&chunk);
}
Ok(all_bytes)
}
}
}
pub mod get_metadata_queue {
@@ -234,7 +234,7 @@ mod api {
#[derive(Debug, Deserialize, Serialize)]
pub struct Metadata {
pub id: uuid::Uuid,
pub song_queue_id: uuid::Uuid,
pub album: String,
pub album_artist: String,
pub artist: String,