Compare commits

...

6 Commits

Author SHA1 Message Date
phoenix 9372b8ea07 Update (#2)
songparser / Check (push) Successful in 2m3s
songparser / Rustfmt (push) Successful in 52s
songparser / build (push) Successful in 2m0s
songparser / Clippy (push) Successful in 2m12s
Reviewed-on: #2
2026-07-07 22:49:06 -04:00
phoenix 02cc833cd9 Update rust (#1)
Rust Build / Check (push) Successful in 1m2s
Rust Build / Rustfmt (push) Successful in 57s
Rust Build / Test Suite (push) Successful in 1m9s
Rust Build / Clippy (push) Successful in 1m22s
Rust Build / build (push) Successful in 2m6s
Rust Build / Check (pull_request) Successful in 53s
Rust Build / Rustfmt (pull_request) Successful in 43s
Rust Build / Test Suite (pull_request) Successful in 1m35s
Rust Build / Clippy (pull_request) Successful in 2m26s
Rust Build / build (pull_request) Successful in 2m33s
Reviewed-on: #1
2026-05-22 11:21:58 -04:00
phoenix 6a905c7ec6 Update rust (#72)
Reviewed-on: #72
Co-authored-by: phoenix <mail@kundeng.us>
Co-committed-by: phoenix <mail@kundeng.us>
2026-04-05 17:32:13 -04:00
phoenix 36c079fd87 tsk-68: Saving file_type from CoverArt (#70)
Closes #68

Reviewed-on: #70
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-30 20:25:38 +00:00
phoenix 73eedf829d icarus_models version bump (#69)
Reviewed-on: #69
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-30 19:36:06 +00:00
phoenix 9b6ccb032f Refactoring (#67)
Reviewed-on: #67
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-26 19:49:30 +00:00
15 changed files with 830 additions and 801 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
ROOT_DIRECTORY=/usr/local/bin
ICARUS_BASE_API_URL=http://api:3000
ICARUS_AUTH_BASE_API_URL=http://auth_api:3000
ICARUS_BASE_API_URL=http://api:8000
ICARUS_AUTH_BASE_API_URL=http://auth_api:8001
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
+4
View File
@@ -0,0 +1,4 @@
ROOT_DIRECTORY=/tmp
ICARUS_BASE_API_URL=http://localhost:8000
ICARUS_AUTH_BASE_API_URL=http://localhost:8001
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
+2 -2
View File
@@ -10,14 +10,14 @@ jobs:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 0 # Important for git describe --tags
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.90.0
toolchain: 1.96.1
components: cargo
- name: Extract Version from Cargo.toml
+17 -30
View File
@@ -1,24 +1,27 @@
name: Rust Build
name: songparser
on:
push:
branches:
- main
- devel
pull_request:
branches:
- main
- devel
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.90.0
toolchain: 1.96.1
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -28,33 +31,16 @@ jobs:
ssh-add -v ~/.ssh/gitlab_deploy_key
cargo check
test:
name: Test Suite
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v5
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.90.0
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key
cargo test
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.90.0
toolchain: 1.96.1
- uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt
- run: |
mkdir -p ~/.ssh
@@ -70,10 +56,11 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.90.0
toolchain: 1.96.1
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: |
mkdir -p ~/.ssh
@@ -89,10 +76,11 @@ jobs:
runs-on: ubuntu-24.04
needs: setup_ssh
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.90.0
toolchain: 1.96.1
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
@@ -101,4 +89,3 @@ jobs:
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key
cargo build --release
-39
View File
@@ -1,39 +0,0 @@
stages:
- build
- test
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- mv "$SSH_DEPLOY_KEY" gitlab_deploy_key # copies the file from the variable.
- chmod 600 gitlab_deploy_key
- ssh-add gitlab_deploy_key
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host gitlab.com\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- echo "$KNOWN_HOSTS" >> ~/.ssh/known_hosts
build:
stage: build
image: rust:1.85
script:
- cargo build --release
artifacts:
paths:
- target/release/songparser
expire_in: 1 week
cache:
key: "cargo-cache"
paths:
- target/
- ~/.cargo/
test:
stage: test
image: rust:latest
script:
- cargo test
cache:
key: "cargo-cache"
paths:
- target/
- ~/.cargo/
Generated
+674 -553
View File
File diff suppressed because it is too large Load Diff
+12 -12
View File
@@ -1,18 +1,18 @@
[package]
name = "songparser"
version = "0.4.9"
version = "0.6.1"
edition = "2024"
rust-version = "1.90"
rust-version = "1.95"
[dependencies]
tokio = { version = "1.47.1", features = ["full"] }
futures = { version = "0.3.31" }
reqwest = { version = "0.12.23", features = ["json", "stream", "multipart"] }
tokio = { version = "1.52.3", features = ["full"] }
futures = { version = "0.3.32" }
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
openssl = { version = "0.10.81", features = ["vendored"] }
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.3" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" }
serde_json = { version = "1.0.150" }
time = { version = "0.3.53", features = ["macros", "serde"] }
uuid = { version = "1.23.4", features = ["v4", "serde"] }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.6.1" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.11.3" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.8.0" }
+3 -29
View File
@@ -1,63 +1,37 @@
# 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.90 as builder
FROM rust:1.96.1 as builder
# Set the working directory inside the container
WORKDIR /usr/src/app
# Install build dependencies if needed (e.g., git for cloning)
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl3 \
ca-certificates \
openssh-client git \
&& rm -rf /var/lib/apt/lists/*
# << --- ADD HOST KEY HERE --- >>
# Replace 'yourgithost.com' with the actual hostname (e.g., github.com)
RUN mkdir -p -m 0700 ~/.ssh && \
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
# Copy Cargo manifests
COPY Cargo.toml Cargo.lock ./
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
RUN --mount=type=ssh mkdir src && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release --quiet && \
rm -rf src target/release/deps/songparser* # Clean up dummy build artifacts (replace songparser)
rm -rf src target/release/deps/songparser*
# Copy the actual source code
COPY src ./src
# If you have other directories like `templates` or `static`, copy them too
COPY .env ./.env
# << --- SSH MOUNT ADDED HERE --- >>
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
# Mount the SSH agent socket for this command
RUN --mount=type=ssh \
cargo build --release --quiet
# Stage 2: Create the final, smaller runtime image
# Use a minimal base image like debian-slim or even distroless for security/size
FROM ubuntu:24.04
FROM debian:trixie-slim
# Install runtime dependencies if needed (e.g., SSL certificates)
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /usr/local/bin
# Copy the compiled binary from the builder stage
# Replace 'songparser' with the actual name of your binary (usually the crate name)
COPY --from=builder /usr/src/app/target/release/songparser .
# Copy other necessary files like .env (if used for runtime config) or static assets
# It's generally better to configure via environment variables in Docker though
COPY --from=builder /usr/src/app/.env .
# Set the command to run your application
# Ensure this matches the binary name copied above
CMD ["./songparser"]
+4 -5
View File
@@ -1,12 +1,11 @@
version: '3.8' # Use a recent version
services:
# Your Rust Application Service
songparser:
build: # Tells docker-compose to build the Dockerfile in the current directory
build:
context: .
ssh: ["default"] # Uses host's SSH agent
container_name: songparser # Optional: Give the container a specific name
ssh: ["default"]
container_name: songparser
env_file:
- .env
restart: unless-stopped # Optional: Restart policy
restart: unless-stopped
+6 -19
View File
@@ -1,5 +1,4 @@
pub mod fetch_next_queue_item {
pub async fn fetch_next_queue_item(
app: &crate::config::App,
) -> Result<reqwest::Response, reqwest::Error> {
@@ -12,9 +11,7 @@ pub mod fetch_next_queue_item {
}
pub mod response {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
@@ -22,7 +19,7 @@ pub mod fetch_next_queue_item {
pub user_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
@@ -78,14 +75,9 @@ pub mod get_metadata_queue {
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let endpoint = String::from("api/v2/song/metadata/queue");
let api_url = format!("{}/{endpoint}", app.uri);
let api_url = format!("{}/{endpoint}?song_queue_id={song_queue_id}", app.uri);
let (key, header) = super::auth_header(app).await;
client
.get(api_url)
.query(&[("song_queue_id", song_queue_id)])
.header(key, header)
.send()
.await
client.get(api_url).header(key, header).send().await
}
pub mod response {
@@ -131,14 +123,9 @@ pub mod get_coverart_queue {
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let endpoint = String::from("api/v2/coverart/queue");
let api_url = format!("{}/{endpoint}", app.uri);
let api_url = format!("{}/{endpoint}?song_queue_id={song_queue_id}", app.uri);
let (key, header) = super::auth_header(app).await;
client
.get(api_url)
.query(&[("song_queue_id", song_queue_id)])
.header(key, header)
.send()
.await
client.get(api_url).header(key, header).send().await
}
pub async fn get_data(
+1 -1
View File
@@ -6,7 +6,7 @@ pub async fn get_token(
let api_url = format!("{}/{endpoint}", app.auth_uri);
let payload = serde_json::json!({
"passphrase": icarus_envy::environment::get_service_passphrase().await.value,
"passphrase": icarus_envy::environment::get_service_passphrase().value,
});
match client.post(api_url).json(&payload).send().await {
+3 -7
View File
@@ -15,13 +15,9 @@ impl App {
pub async fn initialize_app_config() -> App {
App {
uri: icarus_envy::environment::get_icarus_base_api_url()
.await
.value,
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
.await
.value,
root_directory: icarus_envy::environment::get_root_directory().await.value,
uri: icarus_envy::environment::get_icarus_base_api_url().value,
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url().value,
root_directory: icarus_envy::environment::get_root_directory().value,
..Default::default()
}
}
-2
View File
@@ -39,8 +39,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
loop {
println!("Token: {:?}", app.token);
if app.token.token_expired() {
println!("Token expired");
app.token = match auth::get_refresh_token(&app).await {
+102 -64
View File
@@ -105,11 +105,12 @@ pub async fn prep_song(
match crate::api::parsing::parse_response_into_bytes(response).await {
Ok(song_bytes) => {
let song = icarus_models::song::Song {
directory: icarus_envy::environment::get_root_directory().await.value,
directory: icarus_envy::environment::get_root_directory().value,
filename: icarus_models::song::generate_filename(
icarus_models::types::MusicTypes::FlacExtension,
icarus_models::types::MusicType::FlacExtension,
true,
),
)
.unwrap(),
data: song_bytes,
..Default::default()
};
@@ -139,67 +140,9 @@ pub async fn prep_song(
.await
{
Ok(response) => {
let id = &response.data[0].id;
let created_at = &response.data[0].created_at;
let metadata = &response.data[0].metadata;
println!("Id: {id:?}");
println!("Metadata: {metadata:?}");
println!("Created at: {created_at:?}");
println!("Getting coverart queue");
match crate::api::get_coverart_queue::get(app, &queued_song.id).await {
Ok(response) => {
match response.json::<crate::api::get_coverart_queue::response::Response>().await {
Ok(response) => {
let coverart_queue = &response.data[0];
let coverart_queue_id = coverart_queue.id;
println!("Coverart queue Id: {coverart_queue_id:?}");
match crate::api::get_coverart_queue::get_data(app, &coverart_queue_id).await {
Ok(response) => match crate::api::parsing::parse_response_into_bytes(response).await {
Ok(coverart_queue_bytes) => {
let (directory, filename) = crate::util::generate_coverart_queue_dir_and_filename(&coverart_queue.file_type).await;
let coverart = icarus_models::coverart::CoverArt {
directory,
filename,
data: coverart_queue_bytes,
..Default::default()
};
coverart.save_to_filesystem().unwrap();
let coverart_queue_fs_path = match coverart.get_path() {
Ok(path) => {
path
}
Err(err) => {
eprintln!("Error: {err:?}");
std::process::exit(-1);
}
};
let queued_coverart = crate::queued_item::QueuedCoverArt {
id: coverart_queue_id,
coverart,
path: coverart_queue_fs_path
};
println!("Saved coverart queue file at: {:?}", queued_coverart.path);
Ok((queued_song, queued_coverart, metadata.clone()))
}
Err(err) => {
Err(err)
}
}
Err(err) => {
Err(err)
}
}
}
Err(err) => {
Err(err)
}
}
}
let bod = &response.data[0];
match process_coverart(app, &queued_song.id, bod).await {
Ok(qc) => Ok((queued_song, qc, bod.metadata.clone())),
Err(err) => Err(err),
}
}
@@ -216,6 +159,101 @@ pub async fn prep_song(
}
}
pub async fn process_coverart(
app: &crate::config::App,
queued_song_id: &uuid::Uuid,
queued_item: &crate::api::get_metadata_queue::response::QueueItem,
) -> Result<crate::queued_item::QueuedCoverArt, reqwest::Error> {
let id = queued_item.id;
let created_at = queued_item.created_at;
let metadata = &queued_item.metadata;
println!("Id: {id:?}");
println!("Metadata: {metadata:?}");
println!("Created at: {created_at:?}");
println!("Getting coverart queue");
match crate::api::get_coverart_queue::get(app, queued_song_id).await {
Ok(response) => {
match response
.json::<crate::api::get_coverart_queue::response::Response>()
.await
{
Ok(response) => {
let coverart_queue = &response.data[0];
let coverart_queue_id = coverart_queue.id;
println!("Coverart queue Id: {coverart_queue_id:?}");
match crate::api::get_coverart_queue::get_data(app, &coverart_queue_id).await {
Ok(response) => {
match crate::api::parsing::parse_response_into_bytes(response).await {
Ok(coverart_queue_bytes) => {
let queued_coverart = init_queued_coverart(
&coverart_queue_id,
&coverart_queue.file_type,
coverart_queue_bytes,
)
.await;
println!(
"Saved coverart queue file at: {:?}",
queued_coverart.path
);
println!(
"Queued CoverArt file type: {:?}",
queued_coverart.coverart.file_type
);
Ok(queued_coverart)
}
Err(err) => Err(err),
}
}
Err(err) => Err(err),
}
}
Err(err) => Err(err),
}
}
Err(err) => Err(err),
}
}
async fn init_queued_coverart(
coverart_queue_id: &uuid::Uuid,
file_type: &str,
bytes: Vec<u8>,
) -> crate::queued_item::QueuedCoverArt {
// TODO: Consider separating song and coverart when saving to the filesystem
let covart_type = if file_type == icarus_meta::detection::coverart::constants::PNG_TYPE {
icarus_models::types::CoverArtType::PngExtension
} else if file_type == icarus_meta::detection::coverart::constants::JPEG_TYPE {
icarus_models::types::CoverArtType::JpegExtension
} else if file_type == icarus_meta::detection::coverart::constants::JPG_TYPE {
icarus_models::types::CoverArtType::JpgExtension
} else {
icarus_models::types::CoverArtType::None
};
let coverart = icarus_models::coverart::CoverArt {
directory: icarus_envy::environment::get_root_directory().value,
filename: match icarus_models::coverart::generate_filename(covart_type, true) {
Ok(filename) => filename,
Err(err) => {
eprintln!("Error generating CoverArt filename: {err:?}");
panic!("Error initializing queued CoverArt");
}
},
file_type: String::from(file_type),
data: bytes,
..Default::default()
};
coverart.save_to_filesystem().unwrap();
let coverart_queue_fs_path = coverart.get_path().unwrap();
crate::queued_item::QueuedCoverArt {
id: *coverart_queue_id,
coverart,
path: coverart_queue_fs_path,
}
}
pub async fn cleanup(
song: &icarus_models::song::Song,
coverart: &icarus_models::coverart::CoverArt,
-36
View File
@@ -4,39 +4,3 @@ pub fn path_buf_to_string(path: &std::path::Path) -> String {
None => String::new(),
}
}
// TODO: Consider having something like this in icarus_models
pub async fn generate_coverart_queue_dir_and_filename(file_type: &str) -> (String, String) {
use rand::Rng;
let mut filename: String = String::new();
let filename_len = 10;
let some_chars: String = String::from("abcdefghij0123456789");
let mut rng = rand::rng();
for _ in 0..filename_len {
let random_number: i32 = rng.random_range(0..=19);
let index = random_number as usize;
let rando_char = some_chars.chars().nth(index);
if let Some(c) = rando_char {
filename.push(c);
}
}
filename += if file_type == icarus_meta::detection::coverart::constants::JPEG_TYPE
|| file_type == icarus_meta::detection::coverart::constants::JPG_TYPE
{
icarus_models::constants::file_extensions::image::JPEGEXTENSION
} else if file_type == icarus_meta::detection::coverart::constants::PNG_TYPE {
icarus_models::constants::file_extensions::image::PNGEXTENSION
} else {
""
};
// TODO: Consider separating song and coverart when saving to the filesystem
let directory = icarus_envy::environment::get_root_directory().await.value;
(directory, filename)
}