From 2b0f857e3f1c9fd30a08f717b10fd7f72def64a6 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 14 Aug 2026 07:12:33 -0400 Subject: [PATCH] Adding code to download coverart --- src/callers/queue/coverart.rs | 95 ++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/src/callers/queue/coverart.rs b/src/callers/queue/coverart.rs index cc73e7e..30bc38e 100644 --- a/src/callers/queue/coverart.rs +++ b/src/callers/queue/coverart.rs @@ -365,45 +365,68 @@ pub mod endpoint { axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, ) -> (axum::http::StatusCode, axum::response::Response) { - match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await { - Ok(data) => { - let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap(); - 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, - file_type.mime.parse().unwrap(), - ); + match repo::data::queue::coverart::get_with_coverart_queue_id(&pool, &id).await { + Ok((_id, file_key, _bucket, _region, _)) => { + let lab_config = crate::util::maze::get_config(); + let lr = labyrinth::Labyrinth { config: lab_config }; - let coverart_type = if file_type.file_type - == simeta::detection::coverart::constants::JPEG_TYPE - { - simodels::types::CoverArtType::JpegExtension - } else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE { - simodels::types::CoverArtType::JpgExtension - } else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE { - simodels::types::CoverArtType::PngExtension - } else { - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::response::Response::default(), - ); - }; - let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap(); - headers.insert( - axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{filename}\"") - .parse() - .unwrap(), - ); + match lr.download(&file_key).await { + Ok(data) => { + let file_type = + simeta::detection::coverart::file_type_from_data(&data).unwrap(); + 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, + file_type.mime.parse().unwrap(), + ); - (axum::http::StatusCode::OK, response) + let coverart_type = if file_type.file_type + == simeta::detection::coverart::constants::JPEG_TYPE + { + simodels::types::CoverArtType::JpegExtension + } else if file_type.file_type + == simeta::detection::coverart::constants::JPG_TYPE + { + simodels::types::CoverArtType::JpgExtension + } else if file_type.file_type + == simeta::detection::coverart::constants::PNG_TYPE + { + simodels::types::CoverArtType::PngExtension + } else { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ); + }; + let filename = + simodels::coverart::generate_filename(coverart_type, true).unwrap(); + headers.insert( + axum::http::header::CONTENT_DISPOSITION, + format!("attachment; filename=\"{filename}\"") + .parse() + .unwrap(), + ); + + (axum::http::StatusCode::OK, response) + } + Err(err) => { + eprintln!("Error: {err:?}"); + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::response::Response::default(), + ) + } + } + } + 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(), - ), } }