tsk-62: Use QueuedSong and QueuedCoverArt to replace references to path of Song and CoverArt #64

Merged
phoenix merged 7 commits from tsk-62 into main 2025-10-22 17:42:01 +00:00
4 changed files with 38 additions and 34 deletions
Showing only changes of commit 12921c26c3 - Show all commits

View File

@@ -193,21 +193,20 @@ 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,
queued_song: &crate::queued_item::QueuedSong,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
println!("Song path: {song_path:?}");
println!("Queued song path: {:?}", queued_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())
reqwest::multipart::Part::bytes(std::fs::read(&queued_song.path).unwrap())
.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:?}");
let (key, header) = crate::api::auth_header(app).await;
@@ -274,15 +273,14 @@ pub mod create_song {
}
pub mod create_coverart {
pub async fn create(
app: &crate::config::App,
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
song: &icarus_models::song::Song,
queued_coverart: &crate::queued_item::QueuedCoverArt,
) -> 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 payload = get_payload(&song.id, &queued_coverart.id);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
@@ -309,12 +307,12 @@ pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
app: &crate::config::App,
song_queue_id: &uuid::Uuid,
queued_song: &crate::queued_item::QueuedSong
) -> 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
"song_queue_id": queued_song.id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
@@ -333,12 +331,12 @@ pub mod wipe_data {
pub mod coverart_queue {
pub async fn wipe_data(
app: &crate::config::App,
coverart_queue_id: &uuid::Uuid,
queued_coverart: &crate::queued_item::QueuedCoverArt
) -> 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
"coverart_queue_id": queued_coverart.id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);

View File

@@ -63,10 +63,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok((
song,
coverart,
(song_queue_id, _song_queue_path),
(coverart_queue_id, _coverart_queue_path),
_metadata,
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
{
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(
app: &config::App,
song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
queued_song: &crate::queued_item::QueuedSong,
queued_coverart: &crate::queued_item::QueuedCoverArt
) -> 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
.json::<api::wipe_data::song_queue::response::Response>()
.await
{
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
.json::<api::wipe_data::coverart_queue::response::Response>()
.await
@@ -178,6 +181,9 @@ async fn some_work(
user_id: &uuid::Uuid,
) -> Result<
(
icarus_models::song::Song,
icarus_models::coverart::CoverArt,
api::get_metadata_queue::response::Metadata,
queued_item::QueuedSong,
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) => {
match api::update_queued_song::update_queued_song(
app,
&song_queue_path,
song_queue_id,
&queued_song,
)
.await
{
@@ -250,19 +255,19 @@ async fn some_work(
println!("Response: {resp:?}");
let mut song = resp.data[0].clone();
song.directory = song_directory;
song.filename = song_filename;
song.directory = queued_song.song.directory.clone();
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(resp) => {
println!("CoverArt sent and successfully parsed response");
println!("json: {resp:?}");
let mut coverart = resp.data[0].clone();
coverart.directory = coverart_queue.directory;
coverart.filename = coverart_queue.filename;
coverart.directory = queued_coverart.coverart.directory.clone();
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(std::io::Error::other(err.to_string()))

View File

@@ -1,3 +1,4 @@
/// Applies metadata to the queued song
pub async fn apply_metadata(
queued_song: &crate::queued_item::QueuedSong,
queued_coverart: &crate::queued_item::QueuedCoverArt,
@@ -109,11 +110,11 @@ pub async fn apply_metadata(
}
// 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)) => {
if exists {
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) => {}
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) => {
if _data.is_empty() {
println!("There was an issue");

View File

@@ -1,11 +1,11 @@
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct QueuedSong {
pub id: uuid::Uuid,
pub song: icarus_models::song::Song,
pub path: String,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct QueuedCoverArt {
pub id: uuid::Uuid,
pub coverart: icarus_models::coverart::CoverArt,