fetch song queue data #21

Merged
phoenix merged 9 commits from fetch_song_queue_data into devel 2025-06-12 18:57:03 +00:00
Showing only changes of commit dba7cae180 - Show all commits

View File

@@ -28,10 +28,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
{
Ok(response) => {
// Process data here...
let all_bytes = api::fetch_song_queue_data::response::parse_response(response).await?;
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;
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);
@@ -69,10 +75,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.filename = song.generate_filename(icarus_models::types::MusicTypes::FlacExtension, true);
song.directory = icarus_envy::environment::get_root_directory().await;
@@ -80,7 +83,11 @@ pub async fn generate_song_queue_dir_and_filename() -> (String, String) {
}
// TODO: Check to see if this is available in icarus_models
pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec<u8>) -> std::path::PathBuf {
pub async fn save_song_to_fs(
directory: &String,
filename: &String,
data: &Vec<u8>,
) -> std::path::PathBuf {
// TODO: Add function to save bytes to a file in icarus_models
// repo
let dir = std::path::Path::new(directory);
@@ -92,7 +99,6 @@ pub async fn save_song_to_fs(directory: &String, filename: &String, data: &Vec<u
save_path
}
mod responses {
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
@@ -138,8 +144,9 @@ mod api {
// use serde::{Deserialize, Serialize};
// pub struct Response {
// }
pub async fn parse_response(response: reqwest::Response) -> Result<Vec<u8>, reqwest::Error> {
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();