Song queue #258

Merged
phoenix merged 14 commits from song_queue into main 2026-08-13 15:27:32 -04:00
2 changed files with 66 additions and 11 deletions
Showing only changes of commit db8e5458ca - Show all commits
+48 -9
View File
@@ -358,14 +358,7 @@ pub mod endpoint {
println!("Id: {song_queue_id}"); println!("Id: {song_queue_id}");
let lab_config = crate::util::maze::get_config(); let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config }; let lr = labyrinth::Labyrinth { config: lab_config };
/*
let data = labyrinth::Data {
raw_data: copied_raw_data,
..Default::default()
};
*/
match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await { match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await {
Ok((id, file_key, _bucket, _region, _)) => match lr.download(&file_key).await { Ok((id, file_key, _bucket, _region, _)) => match lr.download(&file_key).await {
@@ -481,7 +474,7 @@ pub mod endpoint {
) )
)] )]
pub async fn update_song_queue( pub async fn update_song_queue(
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(song_queue_id): axum::extract::Path<uuid::Uuid>,
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
mut multipart: axum::extract::Multipart, mut multipart: axum::extract::Multipart,
) -> ( ) -> (
@@ -512,7 +505,27 @@ pub mod endpoint {
match super::is_song_valid(&raw_data).await { match super::is_song_valid(&raw_data).await {
Ok(valid) => { Ok(valid) => {
if valid { if valid {
match repo::song::update(&pool, &raw_data, &id).await { let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await {
Ok((id, file_key, _bucket, _region, _)) => match lr.delete(&file_key).await {
Ok(_response) => {
let data = labyrinth::Data {
raw_data: raw_data,
..Default::default()
};
let filename = simodels::song::generate_filename(
simodels::types::MusicType::FlacExtension,
true,
)
.unwrap();
let new_file_key = format!("queued/song/{filename}");
match lr.upload(&new_file_key, &data).await {
Ok(_) => {
match repo::data::update_file_key(&pool, &song_queue_id, &new_file_key).await {
Ok(_) => { Ok(_) => {
response.message = response.message =
String::from(super::super::super::response::SUCCESSFUL); String::from(super::super::super::response::SUCCESSFUL);
@@ -527,6 +540,32 @@ pub mod endpoint {
) )
} }
} }
}
Err(err) => {
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
Err(err) => {
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
} else { } else {
response.message = String::from("Invalid song type"); response.message = String::from("Invalid song type");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
+16
View File
@@ -25,6 +25,22 @@ pub async fn insert(
} }
} }
pub async fn update_file_key(pool: &sqlx::PgPool, id: &uuid::Uuid, file_key: &str) -> Result<(), sqlx::Error> {
match sqlx::query(
r#"
UPDATE "songQueueData" SET file_key = $1 WHERE id = $2;
"#,
)
.bind(file_key)
.bind(id)
.execute(pool)
.await
{
Ok(_row) => Ok(()),
Err(_) => Err(sqlx::Error::RowNotFound),
}
}
pub async fn get( pub async fn get(
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
id: &uuid::Uuid, id: &uuid::Uuid,