Next release #13
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1255,7 +1255,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
|
|
||||||
|
26
src/main.rs
26
src/main.rs
@@ -40,7 +40,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// TODO: Cleanup files in local filesystem
|
match cleanup(&song_queue_path, &coverart_queue_path).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Successful cleanup");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
@@ -100,6 +107,23 @@ async fn wipe_data_from_queues(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn cleanup(
|
||||||
|
song_queue_path: &String,
|
||||||
|
coverart_queue_path: &String,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
match the_rest::cleanup::clean_song_queue(song_queue_path) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: Problem cleaning up SongQueue files {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn is_queue_empty(
|
async fn is_queue_empty(
|
||||||
api_url: &String,
|
api_url: &String,
|
||||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||||
|
@@ -123,3 +123,54 @@ 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user