tsk-212: Got functionality working
This commit is contained in:
+41
-2
@@ -485,6 +485,24 @@ pub mod cov_db {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod helper {
|
||||||
|
pub fn is_coverart_file_type_valid(file_type: &String) -> bool {
|
||||||
|
let valid_file_types = vec![
|
||||||
|
String::from("png"),
|
||||||
|
String::from("jpg"),
|
||||||
|
String::from("jpeg"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for valid_file_type in valid_file_types {
|
||||||
|
if valid_file_type == *file_type {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod endpoint {
|
pub mod endpoint {
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
|
||||||
@@ -516,13 +534,33 @@ pub mod endpoint {
|
|||||||
let content_type = field.content_type().unwrap().to_string();
|
let content_type = field.content_type().unwrap().to_string();
|
||||||
let data = field.bytes().await.unwrap();
|
let data = field.bytes().await.unwrap();
|
||||||
let raw_data = data.to_vec();
|
let raw_data = data.to_vec();
|
||||||
|
let file_type =
|
||||||
|
match icarus_meta::detection::coverart::file_type_from_data(&raw_data) {
|
||||||
|
Ok(file_type) => file_type,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
response.message = err.to_string();
|
||||||
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if !super::helper::is_coverart_file_type_valid(&file_type) {
|
||||||
|
response.message = format!("CoverArt file type not supported: {file_type:?}");
|
||||||
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
println!(
|
println!(
|
||||||
"Received file '{}' (name = '{}', content-type = '{}', size = {})",
|
"Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {})",
|
||||||
file_name,
|
file_name,
|
||||||
name,
|
name,
|
||||||
content_type,
|
content_type,
|
||||||
data.len()
|
data.len(),
|
||||||
|
file_type
|
||||||
);
|
);
|
||||||
|
|
||||||
match super::db::insert(&pool, &raw_data).await {
|
match super::db::insert(&pool, &raw_data).await {
|
||||||
@@ -537,6 +575,7 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)),
|
Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
|
|||||||
Reference in New Issue
Block a user