tsk-227: Change statement when evaluating multipart form when queueing song #241
Generated
+1
-1
@@ -964,7 +964,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.23"
|
version = "0.3.24"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.23"
|
version = "0.3.24"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
+62
-52
@@ -139,66 +139,76 @@ pub mod endpoint {
|
|||||||
let mut results: Vec<uuid::Uuid> = Vec::new();
|
let mut results: Vec<uuid::Uuid> = Vec::new();
|
||||||
let mut response = super::response::song_queue::Response::default();
|
let mut response = super::response::song_queue::Response::default();
|
||||||
|
|
||||||
while let Some(field) = multipart.next_field().await.unwrap() {
|
match multipart.next_field().await {
|
||||||
let name = field.name().unwrap().to_string();
|
Ok(multipart_field) => {
|
||||||
let file_name = field.file_name().unwrap().to_string();
|
if let Some(field) = multipart_field {
|
||||||
let content_type = field.content_type().unwrap().to_string();
|
let name = field.name().unwrap().to_string();
|
||||||
let data = field.bytes().await.unwrap();
|
let file_name = field.file_name().unwrap().to_string();
|
||||||
|
let content_type = field.content_type().unwrap().to_string();
|
||||||
|
let data = field.bytes().await.unwrap();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Received file '{}' (name = '{}', content-type = '{}', size = {})",
|
"Received file '{}' (name = '{}', content-type = '{}', size = {})",
|
||||||
file_name,
|
file_name,
|
||||||
name,
|
name,
|
||||||
content_type,
|
content_type,
|
||||||
data.len()
|
data.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
let raw_data: Vec<u8> = data.to_vec();
|
let raw_data: Vec<u8> = data.to_vec();
|
||||||
match super::is_song_valid(&raw_data).await {
|
match super::is_song_valid(&raw_data).await {
|
||||||
Ok(valid) => {
|
Ok(valid) => {
|
||||||
if valid {
|
if valid {
|
||||||
match repo::song::insert(
|
match repo::song::insert(
|
||||||
&pool,
|
&pool,
|
||||||
&raw_data,
|
&raw_data,
|
||||||
&file_name,
|
&file_name,
|
||||||
&crate::repo::queue::song::status::PENDING.to_string(),
|
&crate::repo::queue::song::status::PENDING.to_string(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(queued_song) => {
|
Ok(queued_song) => {
|
||||||
results.push(queued_song);
|
results.push(queued_song);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
return (
|
return (
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::Json(response),
|
axum::Json(response),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response.message = String::from("Invalid song type");
|
||||||
|
return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
Err(err) => {
|
||||||
response.message = String::from("Invalid song type");
|
response.message = err.to_string();
|
||||||
return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response));
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(err) => {
|
response.data = results;
|
||||||
response.message = err.to_string();
|
response.message = if response.data.is_empty() {
|
||||||
return (
|
String::from("Error")
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
} else {
|
||||||
axum::Json(response),
|
String::from(super::super::super::response::SUCCESSFUL)
|
||||||
);
|
};
|
||||||
|
(axum::http::StatusCode::CREATED, axum::Json(response))
|
||||||
|
} else {
|
||||||
|
response.message = String::from("No field found in multipart");
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.data = results;
|
|
||||||
response.message = if response.data.is_empty() {
|
|
||||||
String::from("Error")
|
|
||||||
} else {
|
|
||||||
String::from(super::super::super::response::SUCCESSFUL)
|
|
||||||
};
|
|
||||||
|
|
||||||
(axum::http::StatusCode::CREATED, axum::Json(response))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Endpoint to link a user id to a queued song
|
/// Endpoint to link a user id to a queued song
|
||||||
|
|||||||
Reference in New Issue
Block a user