Formatting
This commit is contained in:
+11
-8
@@ -450,10 +450,7 @@ pub mod endpoint {
|
|||||||
pub async fn fetch_coverart_with_data(
|
pub async fn fetch_coverart_with_data(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
) -> (
|
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||||
axum::http::StatusCode,
|
|
||||||
axum::response::Response,
|
|
||||||
) {
|
|
||||||
match super::db::get_coverart_queue_data_with_id(&pool, &id).await {
|
match super::db::get_coverart_queue_data_with_id(&pool, &id).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let bytes = axum::body::Bytes::from(data);
|
let bytes = axum::body::Bytes::from(data);
|
||||||
@@ -462,13 +459,19 @@ pub mod endpoint {
|
|||||||
// TODO: Address this hard coding for the coverart content type
|
// TODO: Address this hard coding for the coverart content type
|
||||||
headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap());
|
headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap());
|
||||||
// TODO: Make the conent disposition more dynamic
|
// TODO: Make the conent disposition more dynamic
|
||||||
headers.insert(axum::http::header::CONTENT_DISPOSITION, format!("attachment; filename=\"{}.jpg\"", id).parse().unwrap());
|
headers.insert(
|
||||||
|
axum::http::header::CONTENT_DISPOSITION,
|
||||||
|
format!("attachment; filename=\"{}.jpg\"", id)
|
||||||
|
.parse()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
(axum::http::StatusCode::OK, response)
|
(axum::http::StatusCode::OK, response)
|
||||||
}
|
}
|
||||||
Err(_err) => {
|
Err(_err) => (
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::response::Response::default())
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
}
|
axum::response::Response::default(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-16
@@ -1258,9 +1258,14 @@ mod tests {
|
|||||||
"Should not be empty"
|
"Should not be empty"
|
||||||
);
|
);
|
||||||
|
|
||||||
let raw_uri = String::from(crate::callers::endpoints::QUEUECOVERARTDATA);
|
let raw_uri =
|
||||||
|
String::from(crate::callers::endpoints::QUEUECOVERARTDATA);
|
||||||
let end_index = raw_uri.len() - 5;
|
let end_index = raw_uri.len() - 5;
|
||||||
let uri = format!("{}/{}", (&raw_uri[..end_index]).to_string(), resp_coverart_id);
|
let uri = format!(
|
||||||
|
"{}/{}",
|
||||||
|
(&raw_uri[..end_index]).to_string(),
|
||||||
|
resp_coverart_id
|
||||||
|
);
|
||||||
println!("Uri: {:?}", uri);
|
println!("Uri: {:?}", uri);
|
||||||
|
|
||||||
match app
|
match app
|
||||||
@@ -1275,22 +1280,27 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => match resp_to_bytes(response).await {
|
||||||
match resp_to_bytes(response).await {
|
Ok(bytes) => {
|
||||||
Ok(bytes) => {
|
assert_eq!(
|
||||||
assert_eq!(false, bytes.is_empty(), "Downloaded coverart data should not be empty");
|
false,
|
||||||
let temp_file = tempfile::tempdir().expect("Could not create test directory");
|
bytes.is_empty(),
|
||||||
let test_dir = String::from(temp_file.path().to_str().unwrap());
|
"Downloaded coverart data should not be empty"
|
||||||
let new_file = format!("{}/new_image.jpeg", test_dir);
|
);
|
||||||
|
let temp_file = tempfile::tempdir()
|
||||||
|
.expect("Could not create test directory");
|
||||||
|
let test_dir =
|
||||||
|
String::from(temp_file.path().to_str().unwrap());
|
||||||
|
let new_file = format!("{}/new_image.jpeg", test_dir);
|
||||||
|
|
||||||
let mut file = std::fs::File::create(&new_file).unwrap();
|
let mut file =
|
||||||
file.write_all(&bytes).unwrap();
|
std::fs::File::create(&new_file).unwrap();
|
||||||
}
|
file.write_all(&bytes).unwrap();
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
}
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {:?}", err);
|
assert!(false, "Error: {:?}", err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user