Saving changes
This commit is contained in:
53
src/main.rs
53
src/main.rs
@@ -62,7 +62,7 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
|
|||||||
match api::parsing::parse_response_into_bytes(response).await {
|
match api::parsing::parse_response_into_bytes(response).await {
|
||||||
Ok(song_bytes) => {
|
Ok(song_bytes) => {
|
||||||
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
||||||
let save_path = save_song_to_fs(&directory, &filename, &song_bytes).await;
|
let save_path = save_file_to_fs(&directory, &filename, &song_bytes).await;
|
||||||
|
|
||||||
println!("Saved at: {:?}", save_path);
|
println!("Saved at: {:?}", save_path);
|
||||||
|
|
||||||
@@ -89,6 +89,22 @@ async fn process_song(api_url: &String, song_queue_id: &uuid::Uuid) -> Result<()
|
|||||||
let coverart_queue_id = &response.data[0].id;
|
let coverart_queue_id = &response.data[0].id;
|
||||||
println!("Coverart queue Id: {:?}", coverart_queue_id);
|
println!("Coverart queue Id: {:?}", coverart_queue_id);
|
||||||
// TODO: Get queued coverart's data
|
// TODO: Get queued coverart's data
|
||||||
|
match api::get_coverart_queue::get_data(api_url, &coverart_queue_id).await {
|
||||||
|
Ok(response) => match api::parsing::parse_response_into_bytes(response).await {
|
||||||
|
Ok(coverart_queue_bytes) => {
|
||||||
|
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
||||||
|
let save_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await;
|
||||||
|
|
||||||
|
println!("Saved coverart queue file at: {:?}", save_path);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: Apply metadata to the queued song (modifying file)
|
// TODO: Apply metadata to the queued song (modifying file)
|
||||||
// TODO: Update the queued song with the updated queued song
|
// TODO: Update the queued song with the updated queued song
|
||||||
// TODO: Create song
|
// TODO: Create song
|
||||||
@@ -136,8 +152,34 @@ pub async fn generate_song_queue_dir_and_filename() -> (String, String) {
|
|||||||
(song.directory, song.filename)
|
(song.directory, song.filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Consider having something like this in icarus_models
|
||||||
|
pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) {
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
let mut filename: String = String::new();
|
||||||
|
let filename_len = 10;
|
||||||
|
|
||||||
|
let some_chars: String = String::from("abcdefghij0123456789");
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
|
for _i in 0..filename_len {
|
||||||
|
let random_number: i32 = rng.random_range(0..=19);
|
||||||
|
let index = random_number as usize;
|
||||||
|
let rando_char = some_chars.chars().nth(index);
|
||||||
|
|
||||||
|
if let Some(c) = rando_char {
|
||||||
|
filename.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Consider separating song and coverart when saving to the filesystem
|
||||||
|
let directory = icarus_envy::environment::get_root_directory().await;
|
||||||
|
|
||||||
|
(directory, filename)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check to see if this is available in icarus_models
|
// TODO: Check to see if this is available in icarus_models
|
||||||
pub async fn save_song_to_fs(
|
pub async fn save_file_to_fs(
|
||||||
directory: &String,
|
directory: &String,
|
||||||
filename: &String,
|
filename: &String,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
@@ -280,6 +322,13 @@ mod api {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_data(base_url: &String, coverart_queue_id: &uuid::Uuid) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/coverart/queue/data");
|
||||||
|
let api_url = format!("{}/{}/{}", base_url, endpoint, coverart_queue_id);
|
||||||
|
client.get(api_url).send().await
|
||||||
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user