From c60f7a44aad4bb80c67fbcdeb56ea2ca72920581 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 17 Jun 2025 20:54:48 -0400 Subject: [PATCH] Fixed endpoint for getting coverart queue data --- src/callers/coverart.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index fce6d80..218ef49 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -326,6 +326,8 @@ pub mod cov_db { pub mod endpoint { use std::io::Write; + use axum::response::IntoResponse; + pub async fn queue( axum::Extension(pool): axum::Extension, mut multipart: axum::extract::Multipart, @@ -447,15 +449,29 @@ pub mod endpoint { pub async fn fetch_coverart_with_data( axum::Extension(pool): axum::Extension, - axum::extract::Query(params): axum::extract::Query< - super::request::fetch_coverart_with_data::Params, - >, + axum::extract::Path(id): axum::extract::Path, ) -> ( axum::http::StatusCode, - axum::Json, + axum::response::Response, ) { - let mut response = super::response::fetch_coverart_with_data::Response::default(); + match super::db::get_coverart_queue_data_with_id(&pool, &id).await { + Ok(data) => { + let bytes = axum::body::Bytes::from(data); + let mut response = bytes.into_response(); + let headers = response.headers_mut(); + // TODO: Address this hard coding for the coverart content type + headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap()); + // TODO: Make the conent disposition more dynamic + headers.insert(axum::http::header::CONTENT_DISPOSITION, format!("attachment; filename=\"{}.jpg\"", id).parse().unwrap()); + (axum::http::StatusCode::OK, response) + } + Err(_err) => { + (axum::http::StatusCode::BAD_REQUEST, axum::response::Response::default()) + } + } + + /* match params.id { Some(id) => match super::db::get_coverart_queue_data_with_id(&pool, &id).await { Ok(cover_art_queue) => { @@ -491,6 +507,7 @@ pub mod endpoint { } }, } + */ } pub async fn create_coverart(