Compare commits

...

2 Commits

Author SHA1 Message Date
6d54664a81 icarus_models ver_bump (#49)
All checks were successful
Rust Build / Check (push) Successful in 36s
Rust Build / Rustfmt (push) Successful in 38s
Rust Build / Test Suite (push) Successful in 43s
Rust Build / Clippy (push) Successful in 1m25s
Rust Build / build (push) Successful in 2m16s
Reviewed-on: #49
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-11 23:15:29 +00:00
b2f702c24c icarus_envy version bump (#48)
All checks were successful
Rust Build / Check (push) Successful in 35s
Rust Build / Test Suite (push) Successful in 33s
Rust Build / Rustfmt (push) Successful in 30s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 37s
Reviewed-on: #48
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-10 19:35:40 +00:00
4 changed files with 56 additions and 106 deletions

10
Cargo.lock generated
View File

@@ -516,8 +516,8 @@ dependencies = [
[[package]]
name = "icarus_envy"
version = "0.3.2"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd"
version = "0.4.1"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.4.1-main-8f0d123db5-006#8f0d123db51b18e9cc4ab5bd39a474ba99bd39c3"
dependencies = [
"const_format",
"dotenvy",
@@ -533,8 +533,8 @@ dependencies = [
[[package]]
name = "icarus_models"
version = "0.5.6"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.6#2d6b550ae6721b41ecc3039799f6a5e873869077"
version = "0.6.6"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.6.6-65-eac7562b80-111#eac7562b80b9f82d21ab737d1e84ba4f12e472dd"
dependencies = [
"josekit",
"rand",
@@ -1320,7 +1320,7 @@ dependencies = [
[[package]]
name = "songparser"
version = "0.3.0"
version = "0.3.2"
dependencies = [
"futures",
"icarus_envy",

View File

@@ -1,6 +1,6 @@
[package]
name = "songparser"
version = "0.3.0"
version = "0.3.2"
edition = "2024"
rust-version = "1.88"
@@ -14,5 +14,5 @@ time = { version = "0.3.41", features = ["macros", "serde"] }
uuid = { version = "1.17.0", features = ["v4", "serde"] }
rand = { version = "0.9.1" }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.6.6-65-eac7562b80-111" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" }

View File

@@ -5,15 +5,17 @@ pub mod the_rest;
pub mod update_queued_song;
pub mod util;
use std::io::Write;
pub const SECONDS_TO_SLEEP: u64 = 5;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut app = config::App {
uri: icarus_envy::environment::get_icarus_base_api_url().await,
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url().await,
uri: icarus_envy::environment::get_icarus_base_api_url()
.await
.value,
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
.await
.value,
..Default::default()
};
println!("Base URL: {:?}", app.uri);
@@ -60,24 +62,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: Do something with the result later
match some_work(&app, &song_queue_id, &user_id).await {
Ok((
_song,
_coverart,
(song_queue_id, song_queue_path),
(coverart_queue_id, coverart_queue_path),
song,
coverart,
(song_queue_id, _song_queue_path),
(coverart_queue_id, _coverart_queue_path),
)) => {
match wipe_data_from_queues(&app, &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:?}");
}
Ok(_) => match cleanup(&song, &coverart).await {
Ok(_) => {
println!("Successful cleanup");
}
}
Err(err) => {
eprintln!("Error: {err:?}");
}
},
Err(err) => {
eprintln!("Error: {err:?}");
}
@@ -110,7 +110,7 @@ mod auth {
let api_url = format!("{}/{endpoint}", app.auth_uri);
let payload = serde_json::json!({
"passphrase": icarus_envy::environment::get_service_passphrase().await,
"passphrase": icarus_envy::environment::get_service_passphrase().await.value,
});
match client.post(api_url).json(&payload).send().await {
@@ -202,17 +202,17 @@ async fn wipe_data_from_queues(
}
async fn cleanup(
song_queue_path: &String,
coverart_queue_path: &String,
song: &icarus_models::song::Song,
coverart: &icarus_models::coverart::CoverArt,
) -> Result<(), std::io::Error> {
match the_rest::cleanup::clean_song_queue(song_queue_path) {
match song.remove_from_filesystem() {
Ok(_) => {}
Err(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(()),
Err(err) => Err(err),
}
@@ -342,7 +342,17 @@ async fn prep_song(
match api::parsing::parse_response_into_bytes(response).await {
Ok(song_bytes) => {
let (directory, filename) = generate_song_queue_dir_and_filename().await;
let song_queue_path = save_file_to_fs(&directory, &filename, &song_bytes).await;
let song = icarus_models::song::Song {
directory,
filename,
data: song_bytes,
..Default::default()
};
let songpath = song.song_path().unwrap_or_default();
let song_queue_path = match song.save_to_filesystem() {
Ok(_) => std::path::Path::new(&songpath),
Err(_err) => std::path::Path::new(""),
};
println!("Saved at: {song_queue_path:?}");
@@ -372,12 +382,17 @@ async fn prep_song(
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 coverart_queue_path = save_file_to_fs(&directory, &filename, &coverart_queue_bytes).await;
let coverart = icarus_models::coverart::CoverArt {
path: directory + "/" + &filename,
data: coverart_queue_bytes,
..Default::default()
};
coverart.save_to_filesystem().unwrap();
let coverart_queue_path = std::path::Path::new(&coverart.path);
println!("Saved coverart queue file at: {coverart_queue_path:?}");
let c_path = util::path_buf_to_string(&coverart_queue_path);
let s_path = util::path_buf_to_string(&song_queue_path);
let c_path = util::path_buf_to_string(coverart_queue_path);
let s_path = util::path_buf_to_string(song_queue_path);
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
}
Err(err) => {
@@ -413,9 +428,12 @@ async fn prep_song(
// 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 = icarus_models::song::generate_filename(
icarus_models::types::MusicTypes::FlacExtension,
true,
);
song.directory = icarus_envy::environment::get_root_directory().await;
song.directory = icarus_envy::environment::get_root_directory().await.value;
(song.directory, song.filename)
}
@@ -444,28 +462,11 @@ pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) {
filename += ".jpeg";
// TODO: Consider separating song and coverart when saving to the filesystem
let directory = icarus_envy::environment::get_root_directory().await;
let directory = icarus_envy::environment::get_root_directory().await.value;
(directory, filename)
}
// TODO: Check to see if this is available in icarus_models
pub 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(
song_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()
}
}