Code formatting
This commit is contained in:
+27
-32
@@ -9,10 +9,7 @@ pub mod response {
|
|||||||
mod db {
|
mod db {
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(pool: &sqlx::PgPool, data: &Vec<u8>) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
data: &Vec<u8>,
|
|
||||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO "coverartQueue" (data) VALUES($1) RETURNING id;
|
INSERT INTO "coverartQueue" (data) VALUES($1) RETURNING id;
|
||||||
@@ -50,38 +47,36 @@ pub mod endpoint {
|
|||||||
|
|
||||||
match multipart.next_field().await {
|
match multipart.next_field().await {
|
||||||
Ok(Some(field)) => {
|
Ok(Some(field)) => {
|
||||||
let name = field.name().unwrap().to_string();
|
let name = field.name().unwrap().to_string();
|
||||||
let file_name = field.file_name().unwrap().to_string();
|
let file_name = field.file_name().unwrap().to_string();
|
||||||
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();
|
||||||
|
|
||||||
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()
|
||||||
);
|
);
|
||||||
|
|
||||||
match super::db::insert(&pool, &raw_data).await {
|
match super::db::insert(&pool, &raw_data).await {
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
response.message = String::from("Successful");
|
response.message = String::from("Successful");
|
||||||
response.data.push(id);
|
response.data.push(id);
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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();
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -622,14 +622,18 @@ mod tests {
|
|||||||
let body = MultipartBody::from(form);
|
let body = MultipartBody::from(form);
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
match app.clone().oneshot(
|
match app
|
||||||
axum::http::Request::builder()
|
.clone()
|
||||||
.method(axum::http::Method::POST)
|
.oneshot(
|
||||||
.uri(crate::callers::endpoints::QUEUECOVERART)
|
axum::http::Request::builder()
|
||||||
.header(axum::http::header::CONTENT_TYPE, content_type)
|
.method(axum::http::Method::POST)
|
||||||
.body(axum::body::Body::from_stream(body))
|
.uri(crate::callers::endpoints::QUEUECOVERART)
|
||||||
.unwrap()
|
.header(axum::http::header::CONTENT_TYPE, content_type)
|
||||||
).await {
|
.body(axum::body::Body::from_stream(body))
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp =
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user