Compare commits
1 Commits
1da416cc37
...
v0.4.1
Author | SHA1 | Date | |
---|---|---|---|
da86c3e054 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1349,7 +1349,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
193
src/api.rs
193
src/api.rs
@@ -1,12 +1,33 @@
|
|||||||
pub async fn fetch_next_queue_item(
|
pub mod fetch_next_queue_item {
|
||||||
|
|
||||||
|
pub async fn fetch_next_queue_item(
|
||||||
app: &crate::config::App,
|
app: &crate::config::App,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||||
let api_url = format!("{}/{fetch_endpoint}", app.uri);
|
let api_url = format!("{}/{fetch_endpoint}", app.uri);
|
||||||
let (key, header) = auth_header(app).await;
|
let (key, header) = super::auth_header(app).await;
|
||||||
|
|
||||||
client.get(api_url).header(key, header).send().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(
|
||||||
@@ -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>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
57
src/main.rs
57
src/main.rs
@@ -1,8 +1,5 @@
|
|||||||
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;
|
||||||
@@ -59,7 +56,6 @@ 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,
|
||||||
@@ -174,15 +170,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 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
|
Ok(response) => match response
|
||||||
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
.json::<api::wipe_data::song_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_resp) => {
|
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
|
Ok(inner_response) => match inner_response
|
||||||
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
.json::<api::wipe_data::coverart_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_inner_resp) => {
|
Ok(_inner_resp) => {
|
||||||
@@ -220,11 +216,11 @@ async fn cleanup(
|
|||||||
|
|
||||||
async fn is_queue_empty(
|
async fn is_queue_empty(
|
||||||
app: &config::App,
|
app: &config::App,
|
||||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
) -> Result<(bool, api::fetch_next_queue_item::response::SongQueueItem), reqwest::Error> {
|
||||||
match api::fetch_next_queue_item(app).await {
|
match api::fetch_next_queue_item::fetch_next_queue_item(app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
.json::<api::fetch_next_queue_item::response::SongQueueItem>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@@ -255,10 +251,15 @@ 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_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 {
|
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match update_queued_song::update_queued_song(
|
match api::update_queued_song::update_queued_song(
|
||||||
app,
|
app,
|
||||||
&song_queue_path,
|
&song_queue_path,
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
@@ -267,7 +268,7 @@ async fn some_work(
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<update_queued_song::response::Response>()
|
.json::<api::update_queued_song::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_inner_response) => {
|
Ok(_inner_response) => {
|
||||||
@@ -276,25 +277,29 @@ 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 the_rest::create_song::create(
|
match api::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::<the_rest::create_song::response::Response>()
|
.json::<api::create_song::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
println!("Response: {resp:?}");
|
println!("Response: {resp:?}");
|
||||||
|
|
||||||
let song = &resp.data[0];
|
let mut song = resp.data[0].clone();
|
||||||
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await {
|
song.directory = song_directory;
|
||||||
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
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) => {
|
Ok(resp) => {
|
||||||
println!("CoverArt sent and successfully parsed response");
|
println!("CoverArt sent and successfully parsed response");
|
||||||
println!("json: {resp:?}");
|
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)))
|
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -329,7 +334,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,
|
||||||
@@ -341,10 +346,11 @@ 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 (directory, filename) = generate_song_queue_dir_and_filename().await;
|
let (song_directory, song_filename) =
|
||||||
|
generate_song_queue_dir_and_filename().await;
|
||||||
let song = icarus_models::song::Song {
|
let song = icarus_models::song::Song {
|
||||||
directory,
|
directory: song_directory,
|
||||||
filename,
|
filename: song_filename,
|
||||||
data: song_bytes,
|
data: song_bytes,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -392,8 +398,7 @@ 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);
|
||||||
let s_path = util::path_buf_to_string(song_queue_path);
|
Ok(((song.directory, song.filename), c_path, metadata.clone(), *coverart_queue_id))
|
||||||
Ok((s_path, c_path, metadata.clone(), *coverart_queue_id))
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
Err(err)
|
Err(err)
|
||||||
|
@@ -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>,
|
|
||||||
}
|
|
||||||
}
|
|
128
src/the_rest.rs
128
src/the_rest.rs
@@ -1,128 +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>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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>,
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user