diff --git a/src/callers/song.rs b/src/callers/song.rs index a4333aa..d18ecaf 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -331,9 +331,11 @@ pub mod endpoint { match lr.download(&song.file_key).await { Ok(data) => { - song.filename = - simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true) - .unwrap(); + song.filename = simodels::song::generate_filename( + simodels::types::MusicType::FlacExtension, + true, + ) + .unwrap(); // Will no longer be needed with s3 song.directory = sienvy::environment::get_root_directory().value; song.data = data; @@ -344,15 +346,22 @@ pub mod endpoint { let path = std::path::Path::new(&song_path); if !path.starts_with(&song.directory) || !path.exists() { - return Err((axum::http::StatusCode::NOT_FOUND, "File not found")); + return Err(( + axum::http::StatusCode::NOT_FOUND, + "File not found", + )); } let file = match tokio::fs::File::open(&path).await { Ok(file) => file, - Err(_) => return Err((axum::http::StatusCode::NOT_FOUND, "File not found")), + Err(_) => { + return Err(( + axum::http::StatusCode::NOT_FOUND, + "File not found", + )); + } }; - let file_size = match file.metadata().await { Ok(meta) => meta.len(), Err(_) => { @@ -373,9 +382,7 @@ pub mod endpoint { .body(axum::body::Body::from_stream(stream)) .unwrap(); match song.remove_from_filesystem() { - Ok(_) => { - Ok(rep) - } + Ok(_) => Ok(rep), Err(err) => { eprintln!("Error: {err:?}"); Err(( @@ -386,8 +393,8 @@ pub mod endpoint { } } Err(err) => { - eprintln!("Error: {err:?}"); - Err(( + eprintln!("Error: {err:?}"); + Err(( axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Could not find file", )) @@ -395,8 +402,8 @@ pub mod endpoint { } } Err(err) => { - eprintln!("Error: {err:?}"); - Err(( + eprintln!("Error: {err:?}"); + Err(( axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Could not find file", )) @@ -406,7 +413,7 @@ pub mod endpoint { Err(_err) => Err(( axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Could not find file", - )) + )), } } @@ -425,8 +432,11 @@ pub mod endpoint { axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, ) -> (axum::http::StatusCode, axum::response::Response) { + let lab_config = crate::util::maze::get_config(); + let lr = labyrinth::Labyrinth { config: lab_config }; + match repo::song::get_song(&pool, &id).await { - Ok(song) => match simodels::song::io::to_data(&song) { + Ok(song) => match lr.download(&song.file_key).await { Ok(data) => { let bytes = axum::body::Bytes::from(data); let mut response = bytes.into_response(); @@ -475,6 +485,8 @@ pub mod endpoint { axum::Json, ) { let mut response = super::response::delete_song::Response::default(); + let lab_config = crate::util::maze::get_config(); + let lr = labyrinth::Labyrinth { config: lab_config }; match repo::song::get_song(&pool, &id).await { Ok(song) => { @@ -498,7 +510,8 @@ pub mod endpoint { match repo::coverart::delete_coverart(&pool, &coverart.id).await { Ok(deleted_coverart) => { - match song.remove_from_filesystem() { + // match song.remove_from_filesystem() { + match lr.delete(&song.file_key).await { Ok(_) => match coverart.remove_from_filesystem() { Ok(_) => { response.message = String::from( @@ -516,7 +529,7 @@ pub mod endpoint { } }, Err(err) => { - response.message = err.to_string(); + eprintln!("Error: {err:?}"); (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) } }