Compare commits

...

19 Commits

Author SHA1 Message Date
66c3b0029e Version bump
All checks were successful
Rust Build / Check (pull_request) Successful in 32s
Rust Build / Test Suite (pull_request) Successful in 7m1s
Rust Build / Rustfmt (pull_request) Successful in 8m20s
Rust Build / Clippy (pull_request) Successful in 1m46s
Rust Build / build (pull_request) Successful in 3m11s
2025-10-13 21:55:24 -04:00
f174239c2e Code formatting 2025-10-13 21:54:52 -04:00
c64ecd8a54 Removed file 2025-10-13 21:53:16 -04:00
8c400ed11d Code refactoring 2025-10-13 21:52:06 -04:00
c8eb9521f7 Removing file 2025-10-13 21:50:00 -04:00
0883def735 Code change 2025-10-13 21:49:48 -04:00
f4972c8caf Code refactoring 2025-10-13 21:47:05 -04:00
d55f3b2e46 Removed file 2025-10-13 21:45:31 -04:00
74948ff8a4 Change 2025-10-13 21:45:21 -04:00
988dfe9379 Fixed the bug 2025-10-13 21:42:57 -04:00
c37ecaa8dc Assigned values to directory and filename member fields 2025-10-13 21:15:02 -04:00
1da416cc37 Merge branch 'main' of git.kundeng.us:phoenix/songparser
All checks were successful
Rust Build / Check (pull_request) Successful in 26m11s
Rust Build / Test Suite (pull_request) Successful in 9m58s
Rust Build / Rustfmt (pull_request) Successful in 27s
Rust Build / Clippy (pull_request) Successful in 40m39s
Rust Build / build (pull_request) Successful in 10m58s
2025-10-13 16:15:14 -04:00
acbeb31792 tsk-47: Rust version bump (#51)
All checks were successful
Rust Build / Check (push) Successful in 6m6s
Rust Build / Test Suite (push) Successful in 1m29s
Rust Build / build (push) Successful in 2m27s
Rust Build / Rustfmt (push) Successful in 18m37s
Rust Build / Clippy (push) Successful in 14m56s
Closes #47

Reviewed-on: #51
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-12 22:04:09 +00:00
6041d7d6c6 dependency update (#50)
All checks were successful
Rust Build / Check (push) Successful in 2m56s
Rust Build / Test Suite (push) Successful in 1m28s
Rust Build / Clippy (push) Successful in 4m38s
Rust Build / build (push) Successful in 57s
Rust Build / Rustfmt (push) Successful in 7m25s
Reviewed-on: #50
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-12 21:25:39 +00:00
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
96c75b93df Merge branch 'main' of git.kundeng.us:phoenix/songparser 2025-10-11 19:14:27 -04: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
038f8dbd9a Merge branch 'main' of git.kundeng.us:phoenix/songparser 2025-10-10 15:35:15 -04:00
ea6f65a206 icarus_envy version bump
Some checks failed
Rust Build / Check (pull_request) Failing after 1m19s
Rust Build / Test Suite (pull_request) Failing after 1m33s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Failing after 10s
Rust Build / build (pull_request) Failing after 2m43s
2025-10-10 15:16:12 -04:00
10 changed files with 583 additions and 631 deletions

View File

@@ -10,14 +10,14 @@ jobs:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
fetch-depth: 0 # Important for git describe --tags
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.86.0
toolchain: 1.90.0
components: cargo
- name: Extract Version from Cargo.toml

View File

@@ -15,10 +15,10 @@ jobs:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
toolchain: 1.90.0
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -33,10 +33,10 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
toolchain: 1.90.0
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -51,10 +51,10 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
toolchain: 1.90.0
- run: rustup component add rustfmt
- run: |
mkdir -p ~/.ssh
@@ -70,10 +70,10 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
toolchain: 1.90.0
- run: rustup component add clippy
- run: |
mkdir -p ~/.ssh
@@ -89,10 +89,10 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
toolchain: 1.90.0
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key

582
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,18 @@
[package]
name = "songparser"
version = "0.3.0"
version = "0.4.1"
edition = "2024"
rust-version = "1.88"
rust-version = "1.90"
[dependencies]
tokio = { version = "1.45.1", features = ["full"] }
tokio = { version = "1.47.1", features = ["full"] }
futures = { version = "0.3.31" }
reqwest = { version = "0.12.20", features = ["json", "stream", "multipart"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = { version = "1.0.140" }
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" }
reqwest = { version = "0.12.23", features = ["json", "stream", "multipart"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.145" }
time = { version = "0.3.44", features = ["macros", "serde"] }
uuid = { version = "1.18.1", features = ["v4", "serde"] }
rand = { version = "0.9.2" }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.0" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.7.0" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" }

View File

@@ -1,7 +1,7 @@
# Stage 1: Build the application
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
# Using slim variant for smaller base image
FROM rust:1.88 as builder
FROM rust:1.90 as builder
# Set the working directory inside the container
WORKDIR /usr/src/app

View File

@@ -1,12 +1,33 @@
pub async fn fetch_next_queue_item(
app: &crate::config::App,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let fetch_endpoint = String::from("api/v2/song/queue/next");
let api_url = format!("{}/{fetch_endpoint}", app.uri);
let (key, header) = auth_header(app).await;
pub mod fetch_next_queue_item {
client.get(api_url).header(key, header).send().await
pub async fn fetch_next_queue_item(
app: &crate::config::App,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let fetch_endpoint = String::from("api/v2/song/queue/next");
let api_url = format!("{}/{fetch_endpoint}", app.uri);
let (key, header) = super::auth_header(app).await;
client.get(api_url).header(key, header).send().await
}
pub mod response {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
pub user_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
}
}
}
pub async fn auth_header(
@@ -167,3 +188,169 @@ pub mod refresh_token {
}
}
}
pub mod update_queued_song {
pub async fn update_queued_song(
app: &crate::config::App,
song_path: &String,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
println!("Song path: {song_path:?}");
// TODO: Make the filename random
let form = reqwest::multipart::Form::new().part(
"file",
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap())
.file_name("track01.flac"),
);
let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri);
println!("Url: {url:?}");
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).multipart(form).header(key, header);
let response = request.send().await?;
Ok(response)
}
pub mod response {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
pub mod create_song {
pub async fn create(
app: &crate::config::App,
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
user_id: &uuid::Uuid,
song_type: &String,
) -> Result<reqwest::Response, reqwest::Error> {
let payload = serde_json::json!(
{
"album": &metadata_queue.album,
"album_artist": &metadata_queue.album_artist,
"artist": &metadata_queue.artist,
"disc": metadata_queue.disc,
"disc_count": metadata_queue.disc_count,
"duration": metadata_queue.duration,
"genre": &metadata_queue.genre,
"title": &metadata_queue.title,
"track": metadata_queue.track,
"track_count": metadata_queue.track_count,
"date": metadata_queue.year.to_string(),
"audio_type": &song_type,
"user_id": &user_id,
"song_queue_id": &metadata_queue.song_queue_id,
}
);
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song", app.uri);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
}
}
}
pub mod create_coverart {
pub async fn create(
app: &crate::config::App,
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart", app.uri);
let payload = get_payload(song_id, coverart_queue_id);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
request.send().await
}
fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value {
serde_json::json!({
"song_id": &song_id,
"coverart_queue_id": &coverart_queue_id,
})
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
}
}
}
pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
app: &crate::config::App,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"song_queue_id": song_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
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 coverart_queue {
pub async fn wipe_data(
app: &crate::config::App,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"coverart_queue_id": coverart_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
}

View File

@@ -1,19 +1,18 @@
pub mod api;
pub mod config;
pub mod responses;
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);
@@ -57,27 +56,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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, &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 +106,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 {
@@ -174,15 +170,15 @@ async fn wipe_data_from_queues(
song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<(), std::io::Error> {
match the_rest::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
match api::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
Ok(response) => match response
.json::<the_rest::wipe_data::song_queue::response::Response>()
.json::<api::wipe_data::song_queue::response::Response>()
.await
{
Ok(_resp) => {
match the_rest::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
match api::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
Ok(inner_response) => match inner_response
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
.json::<api::wipe_data::coverart_queue::response::Response>()
.await
{
Ok(_inner_resp) => {
@@ -202,17 +198,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),
}
@@ -220,11 +216,11 @@ async fn cleanup(
async fn is_queue_empty(
app: &config::App,
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
match api::fetch_next_queue_item(app).await {
) -> Result<(bool, api::fetch_next_queue_item::response::SongQueueItem), reqwest::Error> {
match api::fetch_next_queue_item::fetch_next_queue_item(app).await {
Ok(response) => {
match response
.json::<responses::fetch_next_queue_item::SongQueueItem>()
.json::<api::fetch_next_queue_item::response::SongQueueItem>()
.await
{
Ok(response) => {
@@ -255,10 +251,15 @@ async fn some_work(
std::io::Error,
> {
match prep_song(app, song_queue_id).await {
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
Ok(((song_directory, song_filename), coverart_queue_path, metadata, coverart_queue_id)) => {
let mut song_queue_path: String = String::new();
let p = std::path::Path::new(&song_directory);
let sp = p.join(&song_filename);
song_queue_path.push_str(sp.to_str().unwrap_or_default());
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
Ok(_applied) => {
match update_queued_song::update_queued_song(
match api::update_queued_song::update_queued_song(
app,
&song_queue_path,
song_queue_id,
@@ -267,7 +268,7 @@ async fn some_work(
{
Ok(response) => {
match response
.json::<update_queued_song::response::Response>()
.json::<api::update_queued_song::response::Response>()
.await
{
Ok(_inner_response) => {
@@ -276,25 +277,29 @@ async fn some_work(
// TODO: Place this somewhere else
let song_type = String::from("flac");
match the_rest::create_song::create(
match api::create_song::create(
app, &metadata, user_id, &song_type,
)
.await
{
Ok(response) => match response
.json::<the_rest::create_song::response::Response>()
.json::<api::create_song::response::Response>()
.await
{
Ok(resp) => {
println!("Response: {resp:?}");
let song = &resp.data[0];
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await {
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
let mut song = resp.data[0].clone();
song.directory = song_directory;
song.filename = song_filename;
match api::create_coverart::create(app, &song.id, &coverart_queue_id).await {
Ok(response) => match response.json::<api::create_coverart::response::Response>().await {
Ok(resp) => {
println!("CoverArt sent and successfully parsed response");
println!("json: {resp:?}");
let coverart = &resp.data[0];
let mut coverart = resp.data[0].clone();
coverart.path = coverart_queue_path.clone();
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
}
Err(err) => {
@@ -329,7 +334,7 @@ async fn prep_song(
song_queue_id: &uuid::Uuid,
) -> Result<
(
String,
(String, String),
String,
api::get_metadata_queue::response::Metadata,
uuid::Uuid,
@@ -341,8 +346,19 @@ async fn prep_song(
// Process data here...
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_directory, song_filename) =
generate_song_queue_dir_and_filename().await;
let song = icarus_models::song::Song {
directory: song_directory,
filename: song_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,13 +388,18 @@ 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);
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
let c_path = util::path_buf_to_string(coverart_queue_path);
// let s_path = util::path_buf_to_string(song_queue_path);
Ok(((song.directory, song.filename), c_path, metadata.clone(), *coverart_queue_id))
}
Err(err) => {
Err(err)
@@ -413,9 +434,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 +468,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

@@ -1,17 +0,0 @@
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
pub user_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
}
}

View File

@@ -1,179 +0,0 @@
// TODO: Refactor this file when this app is functional
pub mod create_song {
pub async fn create(
app: &crate::config::App,
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
user_id: &uuid::Uuid,
song_type: &String,
) -> Result<reqwest::Response, reqwest::Error> {
let payload = serde_json::json!(
{
"album": &metadata_queue.album,
"album_artist": &metadata_queue.album_artist,
"artist": &metadata_queue.artist,
"disc": metadata_queue.disc,
"disc_count": metadata_queue.disc_count,
"duration": metadata_queue.duration,
"genre": &metadata_queue.genre,
"title": &metadata_queue.title,
"track": metadata_queue.track,
"track_count": metadata_queue.track_count,
"date": metadata_queue.year.to_string(),
"audio_type": &song_type,
"user_id": &user_id,
"song_queue_id": &metadata_queue.song_queue_id,
}
);
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song", app.uri);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
}
}
}
pub mod create_coverart {
pub async fn create(
app: &crate::config::App,
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart", app.uri);
let payload = get_payload(song_id, coverart_queue_id);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
request.send().await
}
fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value {
serde_json::json!({
"song_id": &song_id,
"coverart_queue_id": &coverart_queue_id,
})
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
}
}
}
pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
app: &crate::config::App,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"song_queue_id": song_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
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 coverart_queue {
pub async fn wipe_data(
app: &crate::config::App,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"coverart_queue_id": coverart_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
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()
}
}

View File

@@ -1,36 +0,0 @@
pub async fn update_queued_song(
app: &crate::config::App,
song_path: &String,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
println!("Song path: {song_path:?}");
// TODO: Make the filename random
let form = reqwest::multipart::Form::new().part(
"file",
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap())
.file_name("track01.flac"),
);
let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri);
println!("Url: {url:?}");
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).multipart(form).header(key, header);
let response = request.send().await?;
Ok(response)
}
pub mod response {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}