+72
-41
@@ -508,9 +508,12 @@ pub mod endpoint {
|
||||
let lab_config = crate::util::maze::get_config();
|
||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||
|
||||
println!("Valid song");
|
||||
|
||||
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) => {
|
||||
Ok((id, file_key, _bucket, _region, _)) => {
|
||||
match lr.delete(&file_key).await {
|
||||
Ok(_response) => {
|
||||
let data = labyrinth::Data {
|
||||
raw_data: raw_data,
|
||||
..Default::default()
|
||||
@@ -522,44 +525,55 @@ pub mod endpoint {
|
||||
)
|
||||
.unwrap();
|
||||
let new_file_key = format!("queued/song/{filename}");
|
||||
println!("New key: {new_file_key:?}");
|
||||
|
||||
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 =
|
||||
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);
|
||||
response.data.push(id);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
response.data.push(id);
|
||||
(
|
||||
axum::http::StatusCode::OK,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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:?}");
|
||||
eprintln!("Error: {err:?}");
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
@@ -596,7 +610,8 @@ pub mod endpoint {
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Queued song data wiped", body = super::response::wipe_data_from_song_queue::Response),
|
||||
(status = 404, description = "Queued song cannot be found", body = super::response::wipe_data_from_song_queue::Response)
|
||||
(status = 404, description = "Queued song cannot be found", body = super::response::wipe_data_from_song_queue::Response),
|
||||
(status = 500, description = "Error wiping song data", body = super::response::wipe_data_from_song_queue::Response)
|
||||
)
|
||||
)]
|
||||
pub async fn wipe_data_from_song_queue(
|
||||
@@ -607,21 +622,37 @@ pub mod endpoint {
|
||||
axum::Json<super::response::wipe_data_from_song_queue::Response>,
|
||||
) {
|
||||
let mut response = super::response::wipe_data_from_song_queue::Response::default();
|
||||
let id = payload.song_queue_id;
|
||||
let song_queue_id = payload.song_queue_id;
|
||||
|
||||
match repo::song::get_song_queue(&pool, &id).await {
|
||||
Ok(song_queue) => match repo::song::wipe_data(&pool, &song_queue.id).await {
|
||||
Ok(wiped_id) => {
|
||||
response.message = String::from("Success");
|
||||
response.data.push(wiped_id);
|
||||
match repo::song::get_song_queue(&pool, &song_queue_id).await {
|
||||
Ok(_song_queue) => {
|
||||
match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await {
|
||||
Ok((_id, file_key, _bucket, _region, _)) => {
|
||||
let lab_config = crate::util::maze::get_config();
|
||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
match lr.delete(&file_key).await {
|
||||
Ok(_) => {
|
||||
response.message = String::from("Success");
|
||||
response.data.push(song_queue_id);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||
|
||||
+44
-34
@@ -139,46 +139,56 @@ pub mod endpoint {
|
||||
.unwrap();
|
||||
song.directory = sienvy::environment::get_root_directory().value;
|
||||
|
||||
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
||||
Ok(data) => {
|
||||
song.data = data;
|
||||
let dir = std::path::Path::new(&song.directory);
|
||||
if !dir.exists() {
|
||||
println!("Creating directory");
|
||||
match std::fs::create_dir_all(dir) {
|
||||
Ok(_) => {
|
||||
println!("Successfully created directory");
|
||||
let lab_config = crate::util::maze::get_config();
|
||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||
|
||||
match repo_queue::data::get_with_song_queue_id(&pool, &payload.song_queue_id).await {
|
||||
Ok((_id, file_key, _bucket, _region, _)) => match lr.download(&file_key).await {
|
||||
Ok(data) => {
|
||||
song.data = data;
|
||||
let dir = std::path::Path::new(&song.directory);
|
||||
if !dir.exists() {
|
||||
println!("Creating directory");
|
||||
match std::fs::create_dir_all(dir) {
|
||||
Ok(_) => {
|
||||
println!("Successfully created directory");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: Unable to create the directory {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match song.save_to_filesystem() {
|
||||
Ok(_) => match repo::song::insert(&pool, &song).await {
|
||||
Ok((date_created, id)) => {
|
||||
song.id = id;
|
||||
song.date_created = Some(date_created);
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(song);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message =
|
||||
format!("{:?} song {:?}", err.to_string(), song);
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
eprintln!("Error: Unable to create the directory {err:?}");
|
||||
response.message = err.to_string();
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match song.save_to_filesystem() {
|
||||
Ok(_) => match repo::song::insert(&pool, &song).await {
|
||||
Ok((date_created, id)) => {
|
||||
song.id = id;
|
||||
song.date_created = Some(date_created);
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(song);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = format!("{:?} song {:?}", err.to_string(), song);
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
|
||||
@@ -25,7 +25,11 @@ pub async fn insert(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_file_key(pool: &sqlx::PgPool, id: &uuid::Uuid, file_key: &str) -> Result<(), sqlx::Error> {
|
||||
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;
|
||||
|
||||
@@ -252,6 +252,7 @@ pub async fn get_song_queue(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub async fn wipe_data(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
@@ -299,3 +300,4 @@ pub async fn get_data(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<Vec<u8>, s
|
||||
Err(_err) => Err(sqlx::Error::RowNotFound),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user