From e67b7d32db87cb6472d044da5a31f601bbcb67d0 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 12 Jun 2025 14:17:14 -0400 Subject: [PATCH] Simplify code --- src/main.rs | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3056e41..ea96083 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,24 +37,18 @@ async fn main() -> Result<(), Box> { } let mut song = icarus_models::song::Song::default(); - song.data = all_bytes; + // song.data = all_bytes; song.filename = song.generate_filename( icarus_models::types::MusicTypes::FlacExtension, true, ); - // TODO: Add function to save bytes to a file in icarus_models - // repo 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; - let dir = std::path::Path::new(&song.directory); - let save_path = dir.join(&song.filename); - - let mut file = std::fs::File::create(&save_path).unwrap(); - file.write_all(&song.data).unwrap(); - println!("File saved to: {:?}", save_path); // Process data here... @@ -89,6 +83,32 @@ async fn main() -> Result<(), Box> { } } +// TODO: Consider having something like this in icarus_models +pub async fn generate_song_queue_dir_and_filename() -> (String, String) { + let mut song = icarus_models::song::Song::default(); + song.filename = song.generate_filename( + icarus_models::types::MusicTypes::FlacExtension, + true, + ); + + song.directory = icarus_envy::environment::get_root_directory().await; + + (song.directory, song.filename) +} + +// TODO: Check to see if this is available in icarus_models +pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec) -> std::path::PathBuf { + // TODO: Add function to save bytes to a file in icarus_models + // repo + let dir = std::path::Path::new(directory); + let save_path = dir.join(filename); + + let mut file = std::fs::File::create(&save_path).unwrap(); + file.write_all(data).unwrap(); + + save_path +} + mod responses { pub mod fetch_next_queue_item { use serde::{Deserialize, Serialize};