From 0a4d1807e119cac5f79d4072aafe32ff2130304c Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 28 Jul 2025 16:34:25 -0400 Subject: [PATCH] Code formatting --- src/callers/song.rs | 52 +++++++++++++++++++++++++++------------------ src/main.rs | 12 +++++++---- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index 2fd7526..6d8d6e9 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -1060,28 +1060,38 @@ pub mod endpoint { } } - pub async fn download_song(axum::Extension(pool): axum::Extension, - axum::extract::Path(id): axum::extract::Path) - -> (axum::http::StatusCode, axum::response::Response) { - match super::song_db::get_song(&pool, &id).await { - Ok(song) => match song.to_data() { - Ok(data) => { - let bytes = axum::body::Bytes::from(data); - let mut response = bytes.into_response(); - let headers = response.headers_mut(); - headers.insert(axum::http::header::CONTENT_TYPE, "audio/flac".parse().unwrap()); - headers.insert(axum::http::header::CONTENT_DISPOSITION, format!("attachment; filename=\"{id}.flac\"").parse().unwrap()); + pub async fn download_song( + axum::Extension(pool): axum::Extension, + axum::extract::Path(id): axum::extract::Path, + ) -> (axum::http::StatusCode, axum::response::Response) { + match super::song_db::get_song(&pool, &id).await { + Ok(song) => match song.to_data() { + Ok(data) => { + let bytes = axum::body::Bytes::from(data); + let mut response = bytes.into_response(); + let headers = response.headers_mut(); + headers.insert( + axum::http::header::CONTENT_TYPE, + "audio/flac".parse().unwrap(), + ); + headers.insert( + axum::http::header::CONTENT_DISPOSITION, + format!("attachment; filename=\"{id}.flac\"") + .parse() + .unwrap(), + ); - (axum::http::StatusCode::OK, response) - } - Err(_err) => { - (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::response::Response::default()) - } + (axum::http::StatusCode::OK, response) } - Err(_err) => { - (axum::http::StatusCode::NOT_FOUND, axum::response::Response::default()) - } - } + Err(_err) => ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ), + }, + Err(_err) => ( + axum::http::StatusCode::NOT_FOUND, + axum::response::Response::default(), + ), + } } - } diff --git a/src/main.rs b/src/main.rs index 7c5c9b1..6a4a58d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,10 @@ pub mod init { crate::callers::endpoints::STREAMSONG, get(crate::callers::song::endpoint::stream_song), ) - .route(crate::callers::endpoints::DOWNLOADSONG, get(crate::callers::song::endpoint::download_song)) + .route( + crate::callers::endpoints::DOWNLOADSONG, + get(crate::callers::song::endpoint::download_song), + ) } pub async fn app() -> axum::Router { @@ -656,8 +659,8 @@ mod tests { } pub async fn format_url_with_value(endpoint: &str, value: &uuid::Uuid) -> String { - let last = endpoint.len() - 5; - format!("{}/{value}", &endpoint[0..last]) + let last = endpoint.len() - 5; + format!("{}/{value}", &endpoint[0..last]) } // TODO: Change the name of the function to be more expressive and put into it's own module @@ -2025,7 +2028,8 @@ mod tests { let id = test_data::song_id().await.unwrap(); - let uri = super::format_url_with_value(crate::callers::endpoints::DOWNLOADSONG, &id).await; + let uri = + super::format_url_with_value(crate::callers::endpoints::DOWNLOADSONG, &id).await; match app .clone()