Added download coverart endpoint

This commit is contained in:
kdeng00
2025-07-28 16:52:53 -04:00
parent 703fc49f32
commit d8f0c08cee
+34
View File
@@ -646,4 +646,38 @@ pub mod endpoint {
}
}
}
pub async fn download_coverart(axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>) ->
(axum::http::StatusCode, axum::response::Response) {
match super::cov_db::get_coverart(&pool, &id).await {
Ok(coverart) => match coverart.to_data() {
Ok(data) => {
let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response();
let headers = response.headers_mut();
// TODO: Address hard coding
headers.insert(
axum::http::header::CONTENT_TYPE,
"audio/jpg".parse().unwrap(),
);
headers.insert(
axum::http::header::CONTENT_DISPOSITION,
format!("attachment; filename=\"{id}.jpg\"")
.parse()
.unwrap(),
);
(axum::http::StatusCode::OK, response)
}
Err(_err) => {
(axum::http::StatusCode::NOT_FOUND, axum::response::Response::default())
}
}
Err(_err) => {
(axum::http::StatusCode::NOT_FOUND, axum::response::Response::default())
}
}
}
}