tsk-62: Replaced references
This commit is contained in:
24
src/api.rs
24
src/api.rs
@@ -193,21 +193,20 @@ pub mod refresh_token {
|
|||||||
pub mod update_queued_song {
|
pub mod update_queued_song {
|
||||||
pub async fn update_queued_song(
|
pub async fn update_queued_song(
|
||||||
app: &crate::config::App,
|
app: &crate::config::App,
|
||||||
song_path: &String,
|
queued_song: &crate::queued_item::QueuedSong,
|
||||||
song_queue_id: &uuid::Uuid,
|
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
|
|
||||||
println!("Song path: {song_path:?}");
|
println!("Queued song path: {:?}", queued_song.path);
|
||||||
|
|
||||||
// TODO: Make the filename random
|
// TODO: Make the filename random
|
||||||
let form = reqwest::multipart::Form::new().part(
|
let form = reqwest::multipart::Form::new().part(
|
||||||
"file",
|
"file",
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(song_path).unwrap())
|
reqwest::multipart::Part::bytes(std::fs::read(&queued_song.path).unwrap())
|
||||||
.file_name("track01.flac"),
|
.file_name("track01.flac"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri);
|
let url = format!("{}/api/v2/song/queue/{}", app.uri, queued_song.id);
|
||||||
println!("Url: {url:?}");
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
let (key, header) = crate::api::auth_header(app).await;
|
let (key, header) = crate::api::auth_header(app).await;
|
||||||
@@ -274,15 +273,14 @@ pub mod create_song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod create_coverart {
|
pub mod create_coverart {
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
app: &crate::config::App,
|
app: &crate::config::App,
|
||||||
song_id: &uuid::Uuid,
|
song: &icarus_models::song::Song,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
queued_coverart: &crate::queued_item::QueuedCoverArt,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{}/api/v2/coverart", app.uri);
|
let url = format!("{}/api/v2/coverart", app.uri);
|
||||||
let payload = get_payload(song_id, coverart_queue_id);
|
let payload = get_payload(&song.id, &queued_coverart.id);
|
||||||
let (key, header) = crate::api::auth_header(app).await;
|
let (key, header) = crate::api::auth_header(app).await;
|
||||||
let request = client.post(url).json(&payload).header(key, header);
|
let request = client.post(url).json(&payload).header(key, header);
|
||||||
|
|
||||||
@@ -309,12 +307,12 @@ pub mod wipe_data {
|
|||||||
pub mod song_queue {
|
pub mod song_queue {
|
||||||
pub async fn wipe_data(
|
pub async fn wipe_data(
|
||||||
app: &crate::config::App,
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
queued_song: &crate::queued_item::QueuedSong
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
|
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"song_queue_id": song_queue_id
|
"song_queue_id": queued_song.id
|
||||||
});
|
});
|
||||||
let (key, header) = crate::api::auth_header(app).await;
|
let (key, header) = crate::api::auth_header(app).await;
|
||||||
let request = client.patch(url).json(&payload).header(key, header);
|
let request = client.patch(url).json(&payload).header(key, header);
|
||||||
@@ -333,12 +331,12 @@ pub mod wipe_data {
|
|||||||
pub mod coverart_queue {
|
pub mod coverart_queue {
|
||||||
pub async fn wipe_data(
|
pub async fn wipe_data(
|
||||||
app: &crate::config::App,
|
app: &crate::config::App,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
queued_coverart: &crate::queued_item::QueuedCoverArt
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
|
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"coverart_queue_id": coverart_queue_id
|
"coverart_queue_id": queued_coverart.id
|
||||||
});
|
});
|
||||||
let (key, header) = crate::api::auth_header(app).await;
|
let (key, header) = crate::api::auth_header(app).await;
|
||||||
let request = client.patch(url).json(&payload).header(key, header);
|
let request = client.patch(url).json(&payload).header(key, header);
|
||||||
|
37
src/main.rs
37
src/main.rs
@@ -63,10 +63,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok((
|
Ok((
|
||||||
song,
|
song,
|
||||||
coverart,
|
coverart,
|
||||||
(song_queue_id, _song_queue_path),
|
_metadata,
|
||||||
(coverart_queue_id, _coverart_queue_path),
|
queued_song,
|
||||||
|
queued_coverart
|
||||||
|
// (song_queue_id, _song_queue_path),
|
||||||
|
// (coverart_queue_id, _coverart_queue_path),
|
||||||
)) => {
|
)) => {
|
||||||
match wipe_data_from_queues(&app, &song_queue_id, &coverart_queue_id)
|
match wipe_data_from_queues(&app, &queued_song, &queued_coverart)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => match cleanup(&song, &coverart).await {
|
Ok(_) => match cleanup(&song, &coverart).await {
|
||||||
@@ -102,16 +105,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
async fn wipe_data_from_queues(
|
async fn wipe_data_from_queues(
|
||||||
app: &config::App,
|
app: &config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
queued_song: &crate::queued_item::QueuedSong,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
queued_coverart: &crate::queued_item::QueuedCoverArt
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
match api::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
|
match api::wipe_data::song_queue::wipe_data(app, queued_song).await {
|
||||||
Ok(response) => match response
|
Ok(response) => match response
|
||||||
.json::<api::wipe_data::song_queue::response::Response>()
|
.json::<api::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 api::wipe_data::coverart_queue::wipe_data(app, queued_coverart).await {
|
||||||
Ok(inner_response) => match inner_response
|
Ok(inner_response) => match inner_response
|
||||||
.json::<api::wipe_data::coverart_queue::response::Response>()
|
.json::<api::wipe_data::coverart_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
@@ -178,6 +181,9 @@ async fn some_work(
|
|||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
|
icarus_models::song::Song,
|
||||||
|
icarus_models::coverart::CoverArt,
|
||||||
|
api::get_metadata_queue::response::Metadata,
|
||||||
queued_item::QueuedSong,
|
queued_item::QueuedSong,
|
||||||
queued_item::QueuedCoverArt
|
queued_item::QueuedCoverArt
|
||||||
),
|
),
|
||||||
@@ -214,13 +220,12 @@ async fn some_work(
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
match metadata::apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await
|
match metadata::apply_metadata(&queued_song, &queued_coverart, &metadata).await
|
||||||
{
|
{
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match api::update_queued_song::update_queued_song(
|
match api::update_queued_song::update_queued_song(
|
||||||
app,
|
app,
|
||||||
&song_queue_path,
|
&queued_song,
|
||||||
song_queue_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -250,19 +255,19 @@ async fn some_work(
|
|||||||
println!("Response: {resp:?}");
|
println!("Response: {resp:?}");
|
||||||
|
|
||||||
let mut song = resp.data[0].clone();
|
let mut song = resp.data[0].clone();
|
||||||
song.directory = song_directory;
|
song.directory = queued_song.song.directory.clone();
|
||||||
song.filename = song_filename;
|
song.filename = queued_song.song.filename.clone();
|
||||||
|
|
||||||
match api::create_coverart::create(app, &song.id, &coverart_queue_id).await {
|
match api::create_coverart::create(app, &song, &queued_coverart).await {
|
||||||
Ok(response) => match response.json::<api::create_coverart::response::Response>().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 mut coverart = resp.data[0].clone();
|
||||||
coverart.directory = coverart_queue.directory;
|
coverart.directory = queued_coverart.coverart.directory.clone();
|
||||||
coverart.filename = coverart_queue.filename;
|
coverart.filename = queued_coverart.coverart.filename.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, queued_song.clone(), queued_coverart.clone()))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
Err(std::io::Error::other(err.to_string()))
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
/// Applies metadata to the queued song
|
||||||
pub async fn apply_metadata(
|
pub async fn apply_metadata(
|
||||||
queued_song: &crate::queued_item::QueuedSong,
|
queued_song: &crate::queued_item::QueuedSong,
|
||||||
queued_coverart: &crate::queued_item::QueuedCoverArt,
|
queued_coverart: &crate::queued_item::QueuedCoverArt,
|
||||||
@@ -109,11 +110,11 @@ pub async fn apply_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply coverart
|
// Apply coverart
|
||||||
match icarus_meta::meta::coverart::contains_coverart(&queued_coverart.path) {
|
match icarus_meta::meta::coverart::contains_coverart(&queued_song.path) {
|
||||||
Ok((exists, size)) => {
|
Ok((exists, size)) => {
|
||||||
if exists {
|
if exists {
|
||||||
println!("Coverart exists: {size:?} size");
|
println!("Coverart exists: {size:?} size");
|
||||||
match icarus_meta::meta::coverart::remove_coverart(queued_coverart.path) {
|
match icarus_meta::meta::coverart::remove_coverart(&queued_song.path) {
|
||||||
Ok(_data) => {}
|
Ok(_data) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
@@ -121,7 +122,7 @@ pub async fn apply_metadata(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match icarus_meta::meta::coverart::set_coverart(queued_coverart.path, queued_coverart.path) {
|
match icarus_meta::meta::coverart::set_coverart(&queued_song.path, &queued_coverart.path) {
|
||||||
Ok(_data) => {
|
Ok(_data) => {
|
||||||
if _data.is_empty() {
|
if _data.is_empty() {
|
||||||
println!("There was an issue");
|
println!("There was an issue");
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct QueuedSong {
|
pub struct QueuedSong {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
pub song: icarus_models::song::Song,
|
pub song: icarus_models::song::Song,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct QueuedCoverArt {
|
pub struct QueuedCoverArt {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
pub coverart: icarus_models::coverart::CoverArt,
|
pub coverart: icarus_models::coverart::CoverArt,
|
||||||
|
Reference in New Issue
Block a user