Compare commits

...

4 Commits

Author SHA1 Message Date
27e4b30d21 File cleanup post-parsing (#37)
All checks were successful
Rust Build / Check (push) Successful in 34s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 28s
Release Tagging / release (push) Successful in 29s
Rust Build / build (push) Successful in 43s
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Rustfmt (pull_request) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 36s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 37s
Reviewed-on: #37
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-23 20:25:05 +00:00
99bb72ffb2 Removing hard coded user_id (#38)
Some checks failed
Rust Build / Check (push) Failing after 39s
Release Tagging / release (push) Successful in 43s
Rust Build / Test Suite (push) Failing after 36s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Failing after 35s
Rust Build / build (push) Failing after 1m28s
Rust Build / Check (pull_request) Failing after 32s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Failing after 35s
Rust Build / Test Suite (pull_request) Failing after 1m10s
Rust Build / build (pull_request) Failing after 35s
Reviewed-on: #38
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-23 01:18:35 +00:00
111d16515f Wipe data from CoverArt queue (#36)
Some checks failed
Release Tagging / release (push) Successful in 32s
Rust Build / Check (push) Failing after 34s
Rust Build / Test Suite (push) Failing after 37s
Rust Build / Rustfmt (push) Successful in 29s
Rust Build / Clippy (push) Failing after 36s
Rust Build / build (push) Failing after 37s
Rust Build / Check (pull_request) Failing after 1m58s
Rust Build / Test Suite (pull_request) Failing after 1m21s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Failing after 1m7s
Rust Build / build (pull_request) Failing after 2m5s
Reviewed-on: #36
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 20:10:12 +00:00
47bf24180b Wipe data from song queue (#35)
Some checks failed
Release Tagging / release (push) Successful in 33s
Rust Build / Check (push) Failing after 35s
Rust Build / Test Suite (push) Failing after 41s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Failing after 41s
Rust Build / build (push) Failing after 40s
Rust Build / Check (pull_request) Failing after 36s
Rust Build / Test Suite (pull_request) Failing after 37s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Failing after 34s
Rust Build / build (pull_request) Failing after 35s
Reviewed-on: #35
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-07-15 19:49:24 +00:00
5 changed files with 183 additions and 15 deletions

2
Cargo.lock generated
View File

@@ -1255,7 +1255,7 @@ dependencies = [
[[package]]
name = "songparser"
version = "0.2.1"
version = "0.2.4"
dependencies = [
"futures",
"icarus_envy",

View File

@@ -1,6 +1,6 @@
[package]
name = "songparser"
version = "0.2.1"
version = "0.2.4"
edition = "2024"
rust-version = "1.88"

View File

@@ -21,17 +21,38 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Queue is not empty");
println!("SongQueueItem: {song_queue_item:?}");
let song_queue_id = song_queue_item.data[0].id;
let user_id = song_queue_item.data[0].user_id;
// TODO: Do something with the result later
match some_work(&app_base_url, &song_queue_id).await {
match some_work(&app_base_url, &song_queue_id, &user_id).await {
Ok((
song,
coverart,
_song,
_coverart,
(song_queue_id, song_queue_path),
(coverart_queue_id, coverart_queue_path),
)) => {
// TODO: Wipe data from song and coverart queues
// TODO: Cleanup files in local filesystem
match wipe_data_from_queues(
&app_base_url,
&song_queue_id,
&coverart_queue_id,
)
.await
{
Ok(_) => {
match cleanup(&song_queue_path, &coverart_queue_path).await {
Ok(_) => {
println!("Successful cleanup");
}
Err(err) => {
eprintln!("Error: {err:?}");
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
@@ -51,6 +72,58 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
async fn wipe_data_from_queues(
app_base_url: &String,
song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<(), std::io::Error> {
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
Ok(response) => match response
.json::<the_rest::wipe_data::song_queue::response::Response>()
.await
{
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
app_base_url,
coverart_queue_id,
)
.await
{
Ok(inner_response) => match inner_response
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
.await
{
Ok(_inner_resp) => {
println!("Wiped data from CoverArt queue");
println!("Resp: {_inner_resp:?}");
Ok(())
}
Err(err) => Err(std::io::Error::other(err.to_string())),
},
Err(err) => Err(std::io::Error::other(err.to_string())),
},
Err(err) => Err(std::io::Error::other(err.to_string())),
},
Err(err) => Err(std::io::Error::other(err.to_string())),
}
}
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(
api_url: &String,
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
@@ -77,6 +150,7 @@ async fn is_queue_empty(
async fn some_work(
app_base_url: &String,
song_queue_id: &uuid::Uuid,
user_id: &uuid::Uuid,
) -> Result<
(
icarus_models::song::Song,
@@ -105,16 +179,13 @@ async fn some_work(
Ok(_inner_response) => {
println!("Response: {_inner_response:?}");
// TODO: Do not hard code this. Check if one of the existing
// endpoints already have the user_id
let user_id = uuid::Uuid::new_v4();
// TODO: Place this somewhere else
let song_type = String::from("flac");
// Err(std::io::Error::other(err.to_string()))
match the_rest::create_song::create(
app_base_url,
&metadata,
&user_id,
user_id,
&song_type,
)
.await

View File

@@ -6,6 +6,7 @@ pub mod fetch_next_queue_item {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
pub user_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, Serialize)]

View File

@@ -1,6 +1,5 @@
// TODO: Refactor this file when this app is functional
// TODO: Create song
pub mod create_song {
pub async fn create(
base_url: &String,
@@ -44,7 +43,6 @@ pub mod create_song {
}
}
// TODO: Create coverart
pub mod create_coverart {
pub async fn create(
@@ -76,5 +74,103 @@ pub mod create_coverart {
}
}
// TODO: Wipe data from queued song
pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
base_url: &String,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
let payload = serde_json::json!({
"song_queue_id": song_queue_id
});
let request = client.patch(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
// TODO: Wipe data from queued coverart
pub mod coverart_queue {
pub async fn wipe_data(
base_url: &String,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
let payload = serde_json::json!({
"coverart_queue_id": coverart_queue_id
});
let request = client.patch(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
}
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()
}
}