S3 coverart #261
@@ -232,8 +232,11 @@ pub mod endpoint {
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||
let lab_config = crate::util::maze::get_config();
|
||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||
|
||||
match repo::coverart::get_coverart(&pool, &id).await {
|
||||
Ok(coverart) => match simodels::coverart::io::to_data(&coverart) {
|
||||
Ok(coverart) => match lr.download(&coverart.file_key).await {
|
||||
Ok(data) => {
|
||||
let (file_type, img_type) =
|
||||
match simeta::detection::coverart::file_type_from_data(&data) {
|
||||
|
||||
+47
@@ -503,11 +503,19 @@ mod tests {
|
||||
pub const TEST_SONG_01_FILE_KEY: &str = "processed/song/track01.flac";
|
||||
pub const TEST_SONG_02_FILE_KEY: &str = "processed/song/track02.flac";
|
||||
|
||||
pub const TEST_COVERART_01_FILE_KEY: &str = "processed/coverart/Coverart-1.jpg";
|
||||
pub const TEST_COVERART_02_FILE_KEY: &str = "processed/coverart/Coverart-2.jpg";
|
||||
|
||||
pub struct SongBucket {
|
||||
pub file_key: String,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
pub struct CoverArtBucket {
|
||||
pub file_key: String,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
pub async fn upload_test_songs_to_bucket() {
|
||||
let songs = vec![
|
||||
SongBucket {
|
||||
@@ -546,6 +554,44 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn upload_test_coverarts_to_bucket() {
|
||||
let coverarts = vec![
|
||||
CoverArtBucket {
|
||||
file_key: TEST_COVERART_01_FILE_KEY.to_string(),
|
||||
path: "tests/I/Coverart-1.jpg".to_string(),
|
||||
},
|
||||
CoverArtBucket {
|
||||
file_key: TEST_COVERART_02_FILE_KEY.to_string(),
|
||||
path: "tests/I/Coverart-2.jpg".to_string(),
|
||||
},
|
||||
];
|
||||
|
||||
let lab_config = soaricarus_api::util::maze::get_config();
|
||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||
|
||||
for coverart in &coverarts {
|
||||
let p = std::path::Path::new(&coverart.path);
|
||||
match tokio::fs::File::open(p).await {
|
||||
Ok(mut _file) => {
|
||||
let data = labyrinth::Data {
|
||||
filepath: coverart.path.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match lr.upload(&coverart.file_key, &data).await {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_test_songs_from_bucket() {
|
||||
let songs = vec![
|
||||
SongBucket {
|
||||
@@ -633,6 +679,7 @@ mod tests {
|
||||
app: &axum::Router,
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> Result<axum::response::Response, axum::http::Error> {
|
||||
upload_test_coverarts_to_bucket().await;
|
||||
match super::request::upload_coverart_queue_req(&app).await {
|
||||
Ok(response) => {
|
||||
let resp = super::util::get_resp_data::<
|
||||
|
||||
Reference in New Issue
Block a user