@@ -358,14 +358,7 @@ pub mod endpoint {
|
||||
println!("Id: {song_queue_id}");
|
||||
|
||||
let lab_config = crate::util::maze::get_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 {
|
||||
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(
|
||||
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>,
|
||||
mut multipart: axum::extract::Multipart,
|
||||
) -> (
|
||||
@@ -512,7 +505,27 @@ pub mod endpoint {
|
||||
match super::is_song_valid(&raw_data).await {
|
||||
Ok(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(_) => {
|
||||
response.message =
|
||||
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 {
|
||||
response.message = String::from("Invalid song type");
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
|
||||
@@ -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(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
|
||||
Reference in New Issue
Block a user