diff --git a/src/main.rs b/src/main.rs index ea96083..205f1dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::io::Write; -use futures::StreamExt; #[tokio::main] async fn main() -> Result<(), Box> { @@ -26,31 +25,14 @@ async fn main() -> Result<(), Box> { .await { Ok(response) => { - // 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); - } - - let mut song = icarus_models::song::Song::default(); - // song.data = all_bytes; - song.filename = song.generate_filename( - icarus_models::types::MusicTypes::FlacExtension, - true, - ); - - - song.directory = - icarus_envy::environment::get_root_directory().await; - let (directory, filename) = generate_song_queue_dir_and_filename().await; - let _ = save_song_to_fs(&directory, &filename, &all_bytes).await; - - // Process data here... + let all_bytes = api::fetch_song_queue_data::response::parse_response(response).await?; + + let (directory, filename) = generate_song_queue_dir_and_filename().await; + let save_path = save_song_to_fs(&directory, &filename, &all_bytes).await; + + println!("Saved at: {:?}", save_path); + // TODO: Get queued song's metadata // TODO: Get queued coverart @@ -109,6 +91,7 @@ pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec 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) + } } } }