diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 85a1fd8..9af81f3 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -352,28 +352,47 @@ pub mod endpoint { )] pub async fn download_queued_song( axum::Extension(pool): axum::Extension, - axum::extract::Path(id): axum::extract::Path, + axum::extract::Path(song_queue_id): axum::extract::Path, ) -> (axum::http::StatusCode, axum::response::Response) { - println!("Id: {id}"); + println!("Id: {song_queue_id}"); - match repo::song::get_data(&pool, &id).await { - Ok(data) => { - let by = axum::body::Bytes::from(data); - let mut response = by.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(), - ); + let lab_config = crate::util::maze::get_config(); - (axum::http::StatusCode::OK, response) - } + 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 { + Ok(data) => { + let by = axum::body::Bytes::from(data); + let mut response = by.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) => { + eprintln!("Error: {err:?}"); + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ) + } + }, Err(_err) => ( axum::http::StatusCode::BAD_REQUEST, axum::response::Response::default(), diff --git a/src/main.rs b/src/main.rs index 01f4e95..e07b4f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -974,8 +974,9 @@ mod tests { } let songpath = song.song_path().unwrap(); - let raw_uri = - String::from(soaricarus_api::callers::queue::endpoints::QUEUESONGUPDATE); + let raw_uri = String::from( + soaricarus_api::callers::queue::endpoints::QUEUESONGUPDATE, + ); let end_index = raw_uri.len() - 5; let uri = format!( @@ -1992,7 +1993,10 @@ mod tests { let id = test_data::coverart_id().await.unwrap(); - let uri = format!("{}?id={id}", soaricarus_api::callers::endpoints::GETCOVERART); + let uri = format!( + "{}?id={id}", + soaricarus_api::callers::endpoints::GETCOVERART + ); match app .clone() @@ -2126,9 +2130,11 @@ mod tests { let (id, _, _, _) = test_data::song_id().await.unwrap(); - let uri = - super::util::format_url_with_value(soaricarus_api::callers::endpoints::DOWNLOADSONG, &id) - .await; + let uri = super::util::format_url_with_value( + soaricarus_api::callers::endpoints::DOWNLOADSONG, + &id, + ) + .await; match app .clone() @@ -2303,9 +2309,11 @@ mod tests { .await .unwrap(); - let uri = - super::util::format_url_with_value(soaricarus_api::callers::endpoints::DELETESONG, &id) - .await; + let uri = super::util::format_url_with_value( + soaricarus_api::callers::endpoints::DELETESONG, + &id, + ) + .await; match app .clone() diff --git a/src/util/mod.rs b/src/util/mod.rs index f87ee44..0796dd1 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,27 +1,17 @@ - - pub mod maze { pub fn get_config() -> labyrinth::config::Config { + let s3_endpoint_url = sienvy::environment::get_env("S3_ENDPOINT_URL"); + let bucket_name = sienvy::environment::get_env("S3_BUCKET_NAME"); + let region = sienvy::environment::get_env("GARAGE_S3_REGION"); + let access_key_id = sienvy::environment::get_env("GARAGE_DEFAULT_ACCESS_KEY"); + let secret_key = sienvy::environment::get_env("GARAGE_DEFAULT_SECRET_KEY"); - let s3_endpoint_url = - sienvy::environment::get_env("S3_ENDPOINT_URL"); - let bucket_name = - sienvy::environment::get_env("S3_BUCKET_NAME"); - let region = - sienvy::environment::get_env("GARAGE_S3_REGION"); - let access_key_id = sienvy::environment::get_env( - "GARAGE_DEFAULT_ACCESS_KEY", - ); - let secret_key = sienvy::environment::get_env( - "GARAGE_DEFAULT_SECRET_KEY", - ); - - labyrinth::config::Config { - url: s3_endpoint_url.value, - bucket: bucket_name.value, - region: region.value, - access_key_id: access_key_id.value, - secret_key: secret_key.value, - } + labyrinth::config::Config { + url: s3_endpoint_url.value, + bucket: bucket_name.value, + region: region.value, + access_key_id: access_key_id.value, + secret_key: secret_key.value, + } } }