From 578e7e2d99ef6463f27ce353dac7650d8ee46047 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 18 Jun 2025 20:10:16 -0400 Subject: [PATCH] Reorganizing code --- src/main.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23cfb11..7f1b014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, 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, 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,