Compare commits
9 Commits
v0.3.0
...
858d4b62db
Author | SHA1 | Date | |
---|---|---|---|
858d4b62db
|
|||
7502d99d33
|
|||
67abe51cb1
|
|||
6913db3dd8
|
|||
e17588c321
|
|||
1571019ccb
|
|||
6041d7d6c6 | |||
6d54664a81 | |||
b2f702c24c |
@@ -10,14 +10,14 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Important for git describe --tags
|
fetch-depth: 0 # Important for git describe --tags
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.86.0
|
toolchain: 1.90.0
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
|
@@ -15,10 +15,10 @@ jobs:
|
|||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.88.0
|
toolchain: 1.90.0
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
@@ -33,10 +33,10 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.88.0
|
toolchain: 1.90.0
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
@@ -51,10 +51,10 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.88.0
|
toolchain: 1.90.0
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -70,10 +70,10 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.88.0
|
toolchain: 1.90.0
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -89,10 +89,10 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
needs: setup_ssh
|
needs: setup_ssh
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.88.0
|
toolchain: 1.90.0
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
582
Cargo.lock
generated
582
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
24
Cargo.toml
24
Cargo.toml
@@ -1,18 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.90"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.45.1", features = ["full"] }
|
tokio = { version = "1.47.1", features = ["full"] }
|
||||||
futures = { version = "0.3.31" }
|
futures = { version = "0.3.31" }
|
||||||
reqwest = { version = "0.12.20", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0.12.23", features = ["json", "stream", "multipart"] }
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.140" }
|
serde_json = { version = "1.0.145" }
|
||||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
time = { version = "0.3.44", features = ["macros", "serde"] }
|
||||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||||
rand = { version = "0.9.1" }
|
rand = { version = "0.9.2" }
|
||||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" }
|
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.5.6" }
|
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.3.2" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" }
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# Stage 1: Build the application
|
# Stage 1: Build the application
|
||||||
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
||||||
# Using slim variant for smaller base image
|
# 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
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
85
src/main.rs
85
src/main.rs
@@ -5,15 +5,17 @@ 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]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut app = config::App {
|
let mut app = config::App {
|
||||||
uri: icarus_envy::environment::get_icarus_base_api_url().await,
|
uri: icarus_envy::environment::get_icarus_base_api_url()
|
||||||
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url().await,
|
.await
|
||||||
|
.value,
|
||||||
|
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
|
||||||
|
.await
|
||||||
|
.value,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
println!("Base URL: {:?}", app.uri);
|
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
|
// 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:?}");
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ mod auth {
|
|||||||
let api_url = format!("{}/{endpoint}", app.auth_uri);
|
let api_url = format!("{}/{endpoint}", app.auth_uri);
|
||||||
|
|
||||||
let payload = serde_json::json!({
|
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 {
|
match client.post(api_url).json(&payload).send().await {
|
||||||
@@ -202,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),
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,17 @@ async fn prep_song(
|
|||||||
match api::parsing::parse_response_into_bytes(response).await {
|
match api::parsing::parse_response_into_bytes(response).await {
|
||||||
Ok(song_bytes) => {
|
Ok(song_bytes) => {
|
||||||
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
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:?}");
|
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(response) => match api::parsing::parse_response_into_bytes(response).await {
|
||||||
Ok(coverart_queue_bytes) => {
|
Ok(coverart_queue_bytes) => {
|
||||||
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
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:?}");
|
println!("Saved coverart queue file at: {coverart_queue_path:?}");
|
||||||
|
|
||||||
let c_path = util::path_buf_to_string(&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 s_path = util::path_buf_to_string(song_queue_path);
|
||||||
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -413,9 +428,12 @@ 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 = 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)
|
(song.directory, song.filename)
|
||||||
}
|
}
|
||||||
@@ -444,28 +462,11 @@ pub async fn generate_coverart_queue_dir_and_filename() -> (String, String) {
|
|||||||
filename += ".jpeg";
|
filename += ".jpeg";
|
||||||
|
|
||||||
// TODO: Consider separating song and coverart when saving to the filesystem
|
// 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)
|
(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(
|
pub async fn apply_metadata(
|
||||||
song_queue_path: &String,
|
song_queue_path: &String,
|
||||||
coverart_queue_path: &String,
|
coverart_queue_path: &String,
|
||||||
|
@@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user