Compare commits
3 Commits
v0.4.1
...
3c8c3fa55a
Author | SHA1 | Date | |
---|---|---|---|
3c8c3fa55a
|
|||
2b9dab6e1c
|
|||
e1081aef60
|
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.0
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
|
@@ -18,7 +18,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.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
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.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
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.0
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -73,7 +73,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.0
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -92,7 +92,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.88.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
|
||||||
|
514
Cargo.lock
generated
514
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.4.1"
|
version = "0.3.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.88"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["full"] }
|
tokio = { version = "1.47.1", features = ["full"] }
|
||||||
@@ -13,6 +13,6 @@ serde_json = { version = "1.0.145" }
|
|||||||
time = { version = "0.3.44", features = ["macros", "serde"] }
|
time = { version = "0.3.44", features = ["macros", "serde"] }
|
||||||
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||||
rand = { version = "0.9.2" }
|
rand = { version = "0.9.2" }
|
||||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.4.0" }
|
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.7.0" }
|
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.5.0" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" }
|
||||||
|
@@ -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.90 as builder
|
FROM rust:1.88 as builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
203
src/api.rs
203
src/api.rs
@@ -1,33 +1,12 @@
|
|||||||
pub mod fetch_next_queue_item {
|
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 async fn fetch_next_queue_item(
|
client.get(api_url).header(key, header).send().await
|
||||||
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(
|
pub async fn auth_header(
|
||||||
@@ -188,169 +167,3 @@ 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>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
57
src/main.rs
57
src/main.rs
@@ -1,5 +1,8 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod responses;
|
||||||
|
pub mod the_rest;
|
||||||
|
pub mod update_queued_song;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||||
@@ -56,6 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let song_queue_id = song_queue_item.data[0].id;
|
let song_queue_id = song_queue_item.data[0].id;
|
||||||
let user_id = song_queue_item.data[0].user_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 {
|
match some_work(&app, &song_queue_id, &user_id).await {
|
||||||
Ok((
|
Ok((
|
||||||
song,
|
song,
|
||||||
@@ -170,15 +174,15 @@ async fn wipe_data_from_queues(
|
|||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
match api::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
|
match the_rest::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
|
||||||
Ok(response) => match response
|
Ok(response) => match response
|
||||||
.json::<api::wipe_data::song_queue::response::Response>()
|
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_resp) => {
|
Ok(_resp) => {
|
||||||
match api::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
|
match the_rest::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
|
||||||
Ok(inner_response) => match inner_response
|
Ok(inner_response) => match inner_response
|
||||||
.json::<api::wipe_data::coverart_queue::response::Response>()
|
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_inner_resp) => {
|
Ok(_inner_resp) => {
|
||||||
@@ -216,11 +220,11 @@ async fn cleanup(
|
|||||||
|
|
||||||
async fn is_queue_empty(
|
async fn is_queue_empty(
|
||||||
app: &config::App,
|
app: &config::App,
|
||||||
) -> Result<(bool, api::fetch_next_queue_item::response::SongQueueItem), reqwest::Error> {
|
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||||
match api::fetch_next_queue_item::fetch_next_queue_item(app).await {
|
match api::fetch_next_queue_item(app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<api::fetch_next_queue_item::response::SongQueueItem>()
|
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@@ -251,15 +255,10 @@ async fn some_work(
|
|||||||
std::io::Error,
|
std::io::Error,
|
||||||
> {
|
> {
|
||||||
match prep_song(app, song_queue_id).await {
|
match prep_song(app, song_queue_id).await {
|
||||||
Ok(((song_directory, song_filename), coverart_queue_path, metadata, coverart_queue_id)) => {
|
Ok((song_queue_path, 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 {
|
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match api::update_queued_song::update_queued_song(
|
match update_queued_song::update_queued_song(
|
||||||
app,
|
app,
|
||||||
&song_queue_path,
|
&song_queue_path,
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
@@ -268,7 +267,7 @@ async fn some_work(
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<api::update_queued_song::response::Response>()
|
.json::<update_queued_song::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_inner_response) => {
|
Ok(_inner_response) => {
|
||||||
@@ -277,29 +276,25 @@ async fn some_work(
|
|||||||
// TODO: Place this somewhere else
|
// TODO: Place this somewhere else
|
||||||
let song_type = String::from("flac");
|
let song_type = String::from("flac");
|
||||||
|
|
||||||
match api::create_song::create(
|
match the_rest::create_song::create(
|
||||||
app, &metadata, user_id, &song_type,
|
app, &metadata, user_id, &song_type,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => match response
|
Ok(response) => match response
|
||||||
.json::<api::create_song::response::Response>()
|
.json::<the_rest::create_song::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
println!("Response: {resp:?}");
|
println!("Response: {resp:?}");
|
||||||
|
|
||||||
let mut song = resp.data[0].clone();
|
let song = &resp.data[0];
|
||||||
song.directory = song_directory;
|
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await {
|
||||||
song.filename = song_filename;
|
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
||||||
|
|
||||||
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) => {
|
Ok(resp) => {
|
||||||
println!("CoverArt sent and successfully parsed response");
|
println!("CoverArt sent and successfully parsed response");
|
||||||
println!("json: {resp:?}");
|
println!("json: {resp:?}");
|
||||||
let mut coverart = resp.data[0].clone();
|
let coverart = &resp.data[0];
|
||||||
coverart.path = coverart_queue_path.clone();
|
|
||||||
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
|
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -334,7 +329,7 @@ async fn prep_song(
|
|||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
(String, String),
|
String,
|
||||||
String,
|
String,
|
||||||
api::get_metadata_queue::response::Metadata,
|
api::get_metadata_queue::response::Metadata,
|
||||||
uuid::Uuid,
|
uuid::Uuid,
|
||||||
@@ -346,11 +341,10 @@ async fn prep_song(
|
|||||||
// Process data here...
|
// Process data here...
|
||||||
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 (song_directory, song_filename) =
|
let (directory, filename) = generate_song_queue_dir_and_filename().await;
|
||||||
generate_song_queue_dir_and_filename().await;
|
|
||||||
let song = icarus_models::song::Song {
|
let song = icarus_models::song::Song {
|
||||||
directory: song_directory,
|
directory,
|
||||||
filename: song_filename,
|
filename,
|
||||||
data: song_bytes,
|
data: song_bytes,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -398,7 +392,8 @@ async fn prep_song(
|
|||||||
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);
|
||||||
Ok(((song.directory, song.filename), c_path, metadata.clone(), *coverart_queue_id))
|
let s_path = util::path_buf_to_string(song_queue_path);
|
||||||
|
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
Err(err)
|
Err(err)
|
||||||
|
17
src/responses.rs
Normal file
17
src/responses.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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>,
|
||||||
|
}
|
||||||
|
}
|
128
src/the_rest.rs
Normal file
128
src/the_rest.rs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
// 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>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
src/update_queued_song.rs
Normal file
36
src/update_queued_song.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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>,
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user