Compare commits
6 Commits
v0.2.0-dev
...
v0.2.4-dev
Author | SHA1 | Date | |
---|---|---|---|
27e4b30d21 | |||
99bb72ffb2 | |||
111d16515f | |||
47bf24180b | |||
c16ad062d4 | |||
a779e13a77 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -518,8 +518,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "icarus_models"
|
||||
version = "0.5.0"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.0-devel-7958b89abc-111#7958b89abc56bc9262015b3e201ea2906cc8a9ff"
|
||||
version = "0.4.5"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
@@ -1255,7 +1255,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "songparser"
|
||||
version = "0.2.0"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"icarus_envy",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "songparser"
|
||||
version = "0.2.0"
|
||||
version = "0.2.4"
|
||||
edition = "2024"
|
||||
rust-version = "1.88"
|
||||
|
||||
@@ -14,5 +14,5 @@ time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||
rand = { version = "0.9.1" }
|
||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0-devel-f4b71de969-680" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.0-devel-7958b89abc-111" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.5-devel-655d05dabb-111" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.0-devel-d73fba9899-006" }
|
||||
|
131
src/api.rs
Normal file
131
src/api.rs
Normal file
@@ -0,0 +1,131 @@
|
||||
pub async fn fetch_next_queue_item(base_url: &String) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||
let api_url = format!("{base_url}/{fetch_endpoint}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
|
||||
pub mod parsing {
|
||||
use futures::StreamExt;
|
||||
|
||||
pub async fn parse_response_into_bytes(
|
||||
response: reqwest::Response,
|
||||
) -> Result<Vec<u8>, reqwest::Error> {
|
||||
// TODO: At some point, handle the flow if the size is small or
|
||||
// large
|
||||
let mut byte_stream = response.bytes_stream();
|
||||
let mut all_bytes = Vec::new();
|
||||
|
||||
while let Some(chunk) = byte_stream.next().await {
|
||||
let chunk = chunk?;
|
||||
all_bytes.extend_from_slice(&chunk);
|
||||
}
|
||||
|
||||
Ok(all_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod fetch_song_queue_data {
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}/{id}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_metadata_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/metadata/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Metadata {
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
pub album: String,
|
||||
pub album_artist: String,
|
||||
pub artist: String,
|
||||
pub disc: i32,
|
||||
pub disc_count: i32,
|
||||
pub duration: i64,
|
||||
pub genre: String,
|
||||
pub title: String,
|
||||
pub track: i32,
|
||||
pub track_count: i32,
|
||||
pub year: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct QueueItem {
|
||||
pub id: uuid::Uuid,
|
||||
pub metadata: Metadata,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: time::OffsetDateTime,
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<QueueItem>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_coverart_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue/data");
|
||||
let api_url = format!("{base_url}/{endpoint}/{coverart_queue_id}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CoverArtQueue {
|
||||
pub id: uuid::Uuid,
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<CoverArtQueue>,
|
||||
}
|
||||
}
|
||||
}
|
309
src/main.rs
309
src/main.rs
@@ -1,3 +1,5 @@
|
||||
pub mod api;
|
||||
pub mod responses;
|
||||
pub mod the_rest;
|
||||
pub mod update_queued_song;
|
||||
pub mod util;
|
||||
@@ -19,10 +21,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Queue is not empty");
|
||||
println!("SongQueueItem: {song_queue_item:?}");
|
||||
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_base_url, &song_queue_id).await {
|
||||
Ok(_) => {}
|
||||
match some_work(&app_base_url, &song_queue_id, &user_id).await {
|
||||
Ok((
|
||||
_song,
|
||||
_coverart,
|
||||
(song_queue_id, song_queue_path),
|
||||
(coverart_queue_id, coverart_queue_path),
|
||||
)) => {
|
||||
// TODO: Wipe data from song and coverart queues
|
||||
match wipe_data_from_queues(
|
||||
&app_base_url,
|
||||
&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:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
}
|
||||
@@ -41,6 +72,58 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn wipe_data_from_queues(
|
||||
app_base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
|
||||
Ok(response) => match response
|
||||
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
|
||||
app_base_url,
|
||||
coverart_queue_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(inner_response) => match inner_response
|
||||
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_inner_resp) => {
|
||||
println!("Wiped data from CoverArt queue");
|
||||
println!("Resp: {_inner_resp:?}");
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
async fn cleanup(
|
||||
song_queue_path: &String,
|
||||
coverart_queue_path: &String,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match the_rest::cleanup::clean_song_queue(song_queue_path) {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("Error: Problem cleaning up SongQueue files {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
match the_rest::cleanup::clean_coverart_queue(coverart_queue_path) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
async fn is_queue_empty(
|
||||
api_url: &String,
|
||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||
@@ -67,9 +150,18 @@ async fn is_queue_empty(
|
||||
async fn some_work(
|
||||
app_base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<(), std::io::Error> {
|
||||
user_id: &uuid::Uuid,
|
||||
) -> Result<
|
||||
(
|
||||
icarus_models::song::Song,
|
||||
icarus_models::coverart::CoverArt,
|
||||
(uuid::Uuid, String),
|
||||
(uuid::Uuid, String),
|
||||
),
|
||||
std::io::Error,
|
||||
> {
|
||||
match prep_song(app_base_url, song_queue_id).await {
|
||||
Ok((song_queue_path, coverart_queue_path, metadata)) => {
|
||||
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
|
||||
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||
Ok(_applied) => {
|
||||
match update_queued_song::update_queued_song(
|
||||
@@ -86,7 +178,47 @@ async fn some_work(
|
||||
{
|
||||
Ok(_inner_response) => {
|
||||
println!("Response: {_inner_response:?}");
|
||||
Ok(())
|
||||
|
||||
// TODO: Place this somewhere else
|
||||
let song_type = String::from("flac");
|
||||
|
||||
match the_rest::create_song::create(
|
||||
app_base_url,
|
||||
&metadata,
|
||||
user_id,
|
||||
&song_type,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => match response
|
||||
.json::<the_rest::create_song::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(resp) => {
|
||||
println!("Response: {resp:?}");
|
||||
|
||||
let song = &resp.data[0];
|
||||
match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await {
|
||||
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
||||
Ok(resp) => {
|
||||
println!("CoverArt sent and successfully parsed response");
|
||||
println!("json: {resp:?}");
|
||||
let coverart = &resp.data[0];
|
||||
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::other(err.to_string()))
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::other(err.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
@@ -104,7 +236,15 @@ async fn some_work(
|
||||
async fn prep_song(
|
||||
api_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<(String, String, api::get_metadata_queue::response::Metadata), reqwest::Error> {
|
||||
) -> Result<
|
||||
(
|
||||
String,
|
||||
String,
|
||||
api::get_metadata_queue::response::Metadata,
|
||||
uuid::Uuid,
|
||||
),
|
||||
reqwest::Error,
|
||||
> {
|
||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
||||
Ok(response) => {
|
||||
// Process data here...
|
||||
@@ -148,7 +288,7 @@ async fn prep_song(
|
||||
|
||||
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()))
|
||||
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
||||
}
|
||||
Err(err) => {
|
||||
Err(err)
|
||||
@@ -375,158 +515,3 @@ pub async fn apply_metadata(
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
mod responses {
|
||||
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,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct SongQueueItem {
|
||||
pub message: String,
|
||||
pub data: Vec<QueueItem>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod api {
|
||||
pub async fn fetch_next_queue_item(
|
||||
base_url: &String,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||
let api_url = format!("{base_url}/{fetch_endpoint}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
|
||||
pub mod parsing {
|
||||
use futures::StreamExt;
|
||||
|
||||
pub async fn parse_response_into_bytes(
|
||||
response: reqwest::Response,
|
||||
) -> Result<Vec<u8>, reqwest::Error> {
|
||||
// TODO: At some point, handle the flow if the size is small or
|
||||
// large
|
||||
let mut byte_stream = response.bytes_stream();
|
||||
let mut all_bytes = Vec::new();
|
||||
|
||||
while let Some(chunk) = byte_stream.next().await {
|
||||
let chunk = chunk?;
|
||||
all_bytes.extend_from_slice(&chunk);
|
||||
}
|
||||
|
||||
Ok(all_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod fetch_song_queue_data {
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}/{id}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_metadata_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/song/metadata/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Metadata {
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
pub album: String,
|
||||
pub album_artist: String,
|
||||
pub artist: String,
|
||||
pub disc: i32,
|
||||
pub disc_count: i32,
|
||||
pub duration: i64,
|
||||
pub genre: String,
|
||||
pub title: String,
|
||||
pub track: i32,
|
||||
pub track_count: i32,
|
||||
pub year: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct QueueItem {
|
||||
pub id: uuid::Uuid,
|
||||
pub metadata: Metadata,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: time::OffsetDateTime,
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<QueueItem>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_coverart_queue {
|
||||
pub async fn get(
|
||||
base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue");
|
||||
let api_url = format!("{base_url}/{endpoint}");
|
||||
client
|
||||
.get(api_url)
|
||||
.query(&[("song_queue_id", song_queue_id)])
|
||||
.send()
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_data(
|
||||
base_url: &String,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let endpoint = String::from("api/v2/coverart/queue/data");
|
||||
let api_url = format!("{base_url}/{endpoint}/{coverart_queue_id}");
|
||||
client.get(api_url).send().await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CoverArtQueue {
|
||||
pub id: uuid::Uuid,
|
||||
pub song_queue_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<CoverArtQueue>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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>,
|
||||
}
|
||||
}
|
176
src/the_rest.rs
176
src/the_rest.rs
@@ -1,6 +1,176 @@
|
||||
// TODO: Refactor this file when this app is functional
|
||||
|
||||
// TODO: Create song
|
||||
// TODO: Create coverart
|
||||
// TODO: Wipe data from queued song
|
||||
pub mod create_song {
|
||||
pub async fn create(
|
||||
base_url: &String,
|
||||
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!("{base_url}/api/v2/song");
|
||||
|
||||
let request = client.post(url).json(&payload);
|
||||
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(
|
||||
base_url: &String,
|
||||
song_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/coverart");
|
||||
let payload = get_payload(song_id, coverart_queue_id);
|
||||
let request = client.post(url).json(&payload);
|
||||
|
||||
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(
|
||||
base_url: &String,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
|
||||
let payload = serde_json::json!({
|
||||
"song_queue_id": song_queue_id
|
||||
});
|
||||
let request = client.patch(url).json(&payload);
|
||||
|
||||
request.send().await
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<uuid::Uuid>,
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Wipe data from queued coverart
|
||||
pub mod coverart_queue {
|
||||
pub async fn wipe_data(
|
||||
base_url: &String,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
|
||||
let payload = serde_json::json!({
|
||||
"coverart_queue_id": coverart_queue_id
|
||||
});
|
||||
let request = client.patch(url).json(&payload);
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user