Build changes
Some checks failed
Rust Build / Check (pull_request) Successful in 34s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Failing after 39s
Rust Build / build (pull_request) Successful in 41s

This commit is contained in:
2025-10-11 18:56:58 -04:00
parent 60069d9e14
commit cb5cf3a8ca
2 changed files with 23 additions and 100 deletions

View File

@@ -5,8 +5,6 @@ pub mod the_rest;
pub mod update_queued_song; pub mod update_queued_song;
pub mod util; pub mod util;
use std::io::Write;
pub const SECONDS_TO_SLEEP: u64 = 5; pub const SECONDS_TO_SLEEP: u64 = 5;
#[tokio::main] #[tokio::main]
@@ -64,24 +62,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: Do something with the result later // TODO: Do something with the result later
match some_work(&app, &song_queue_id, &user_id).await { match some_work(&app, &song_queue_id, &user_id).await {
Ok(( Ok((
_song, song,
_coverart, coverart,
(song_queue_id, song_queue_path), (song_queue_id, _song_queue_path),
(coverart_queue_id, coverart_queue_path), (coverart_queue_id, _coverart_queue_path),
)) => { )) => {
match wipe_data_from_queues(&app, &song_queue_id, &coverart_queue_id) match wipe_data_from_queues(&app, &song_queue_id, &coverart_queue_id)
.await .await
{ {
Ok(_) => { Ok(_) => match cleanup(&song, &coverart).await {
match cleanup(&song_queue_path, &coverart_queue_path).await {
Ok(_) => { Ok(_) => {
println!("Successful cleanup"); println!("Successful cleanup");
} }
Err(err) => { Err(err) => {
eprintln!("Error: {err:?}"); eprintln!("Error: {err:?}");
} }
} },
}
Err(err) => { Err(err) => {
eprintln!("Error: {err:?}"); eprintln!("Error: {err:?}");
} }
@@ -206,17 +202,17 @@ async fn wipe_data_from_queues(
} }
async fn cleanup( async fn cleanup(
song_queue_path: &String, song: &icarus_models::song::Song,
coverart_queue_path: &String, coverart: &icarus_models::coverart::CoverArt,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
match the_rest::cleanup::clean_song_queue(song_queue_path) { match song.remove_from_filesystem() {
Ok(_) => {} Ok(_) => {}
Err(err) => { Err(err) => {
eprintln!("Error: Problem cleaning up SongQueue files {err:?}"); eprintln!("Error: Problem cleaning up SongQueue files {err:?}");
} }
} }
match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) { match coverart.remove_from_filesystem() {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(err) => Err(err), Err(err) => Err(err),
} }
@@ -353,21 +349,13 @@ async fn prep_song(
..Default::default() ..Default::default()
}; };
let songpath = match song.song_path() { let songpath = match song.song_path() {
Ok(songpath) => { Ok(songpath) => songpath,
songpath Err(_err) => String::new(),
}
Err(_err) => {
String::new()
}
}; };
let song_queue_path = match song.save_to_filesystem() { let song_queue_path = match song.save_to_filesystem() {
Ok(_) => { Ok(_) => std::path::Path::new(&songpath),
std::path::Path::new(&songpath) Err(_err) => std::path::Path::new(""),
}
Err(_err) => {
std::path::Path::new("")
}
}; };
println!("Saved at: {song_queue_path:?}"); println!("Saved at: {song_queue_path:?}");
@@ -445,7 +433,10 @@ async fn prep_song(
// TODO: Consider having something like this in icarus_models // TODO: Consider having something like this in icarus_models
pub async fn generate_song_queue_dir_and_filename() -> (String, String) { pub async fn generate_song_queue_dir_and_filename() -> (String, String) {
let mut song = icarus_models::song::Song::default(); let mut song = icarus_models::song::Song::default();
song.filename = icarus_models::song::generate_filename(icarus_models::types::MusicTypes::FlacExtension, true); song.filename = icarus_models::song::generate_filename(
icarus_models::types::MusicTypes::FlacExtension,
true,
);
song.directory = icarus_envy::environment::get_root_directory().await.value; song.directory = icarus_envy::environment::get_root_directory().await.value;
@@ -481,23 +472,6 @@ pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) {
(directory, filename) (directory, filename)
} }
// TODO: Check to see if this is available in icarus_models
async fn save_file_to_fs(
directory: &String,
filename: &String,
data: &[u8],
) -> 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
}
pub async fn apply_metadata( pub async fn apply_metadata(
song_queue_path: &String, song_queue_path: &String,
coverart_queue_path: &String, coverart_queue_path: &String,

View File

@@ -126,54 +126,3 @@ pub mod wipe_data {
} }
} }
} }
pub mod cleanup {
pub fn clean_song_queue(song_queue_path: &String) -> Result<(), std::io::Error> {
let file_path = std::path::Path::new(song_queue_path);
if file_path.exists() {
match std::fs::remove_file(file_path) {
Ok(_) => {
if check_file_existence(song_queue_path) {
Err(std::io::Error::other(String::from(
"SongQueue file exists after a deletion",
)))
} else {
Ok(())
}
}
Err(err) => Err(std::io::Error::other(err.to_string())),
}
} else {
Err(std::io::Error::other(String::from(
"SongQueue file path does not exists",
)))
}
}
pub fn clean_coverart_queue(coverart_queue_path: &String) -> Result<(), std::io::Error> {
let coverart_file_path = std::path::Path::new(coverart_queue_path);
if coverart_file_path.exists() {
match std::fs::remove_file(coverart_file_path) {
Ok(_) => {
if !check_file_existence(coverart_queue_path) {
Ok(())
} else {
Err(std::io::Error::other(String::from(
"CoverArt file stil exists",
)))
}
}
Err(err) => Err(std::io::Error::other(err.to_string())),
}
} else {
Err(std::io::Error::other(String::from(
"CoverArt file does not exists",
)))
}
}
fn check_file_existence(file_path: &String) -> bool {
let path = std::path::Path::new(file_path);
path.exists()
}
}