tsk-199: Separate CoverArt queue endpoints #219
Generated
+1
-1
@@ -834,7 +834,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.4"
|
version = "0.3.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.3.4"
|
version = "0.3.5"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ Web API for the Icarus project.
|
|||||||
|
|
||||||
|
|
||||||
### Requires
|
### Requires
|
||||||
`icarus_auth` +v0.6.5
|
`icarus_auth` v0.6.x
|
||||||
`songparser` +v0.4.8
|
`songparser` v0.4.x
|
||||||
|
|
||||||
### Compatible with
|
### Compatible with
|
||||||
`icarus-dm` v0.8.4
|
`icarus-dm` v0.8.x
|
||||||
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|||||||
@@ -1,49 +1,4 @@
|
|||||||
// TODO: Separate queue and coverart endpoints
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct CoverArtQueue {
|
|
||||||
pub id: uuid::Uuid,
|
|
||||||
pub file_type: String,
|
|
||||||
pub song_queue_id: uuid::Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod request {
|
pub mod request {
|
||||||
pub mod queue {
|
|
||||||
#[derive(utoipa::ToSchema)]
|
|
||||||
pub struct Request {
|
|
||||||
/// Filename
|
|
||||||
pub file: String,
|
|
||||||
#[schema(rename = "type")]
|
|
||||||
/// File type. Should be a file and not a value
|
|
||||||
pub file_type: String,
|
|
||||||
/// Raw data of the cover art file
|
|
||||||
pub value: Vec<u8>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod link {
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Request {
|
|
||||||
pub coverart_id: uuid::Uuid,
|
|
||||||
pub song_queue_id: uuid::Uuid,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod fetch_coverart_no_data {
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Params {
|
|
||||||
pub id: Option<uuid::Uuid>,
|
|
||||||
pub song_queue_id: Option<uuid::Uuid>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod fetch_coverart_with_data {
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Params {
|
|
||||||
pub id: Option<uuid::Uuid>,
|
|
||||||
pub song_queue_id: Option<uuid::Uuid>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod create_coverart {
|
pub mod create_coverart {
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
@@ -52,13 +7,6 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod wipe_data_from_coverart_queue {
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Request {
|
|
||||||
pub coverart_queue_id: uuid::Uuid,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod get_coverart {
|
pub mod get_coverart {
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
@@ -68,42 +16,6 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Response {
|
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<uuid::Uuid>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod link {
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Id {
|
|
||||||
pub coverart_id: uuid::Uuid,
|
|
||||||
pub song_queue_id: uuid::Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Response {
|
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<Id>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod fetch_coverart_no_data {
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Response {
|
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<super::super::CoverArtQueue>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod fetch_coverart_with_data {
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Response {
|
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<Vec<u8>>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod create_coverart {
|
pub mod create_coverart {
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
@@ -112,14 +24,6 @@ pub mod response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod wipe_data_from_coverart_queue {
|
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
|
||||||
pub struct Response {
|
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<uuid::Uuid>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod get_coverart {
|
pub mod get_coverart {
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
@@ -129,251 +33,12 @@ pub mod response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod helper {
|
|
||||||
pub fn is_coverart_file_type_valid(file_type: &String) -> bool {
|
|
||||||
let valid_file_types = vec![
|
|
||||||
String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE),
|
|
||||||
String::from(icarus_meta::detection::coverart::constants::JPG_TYPE),
|
|
||||||
String::from(icarus_meta::detection::coverart::constants::PNG_TYPE),
|
|
||||||
];
|
|
||||||
|
|
||||||
for valid_file_type in valid_file_types {
|
|
||||||
if valid_file_type == *file_type {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod endpoint {
|
pub mod endpoint {
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
|
||||||
use crate::repo;
|
use crate::repo;
|
||||||
use crate::repo::queue as repo_queue;
|
use crate::repo::queue as repo_queue;
|
||||||
|
|
||||||
/// Endpoint to queue cover art
|
|
||||||
#[utoipa::path(
|
|
||||||
post,
|
|
||||||
path = super::super::endpoints::QUEUECOVERART,
|
|
||||||
request_body(
|
|
||||||
content = super::request::queue::Request,
|
|
||||||
),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Successful", body = super::response::Response),
|
|
||||||
(status = 400, description = "Error queueing cover art", body = super::response::Response)
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub async fn queue(
|
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
|
||||||
mut multipart: axum::extract::Multipart,
|
|
||||||
) -> (
|
|
||||||
axum::http::StatusCode,
|
|
||||||
axum::Json<super::response::Response>,
|
|
||||||
) {
|
|
||||||
let mut response = super::response::Response::default();
|
|
||||||
|
|
||||||
match multipart.next_field().await {
|
|
||||||
Ok(Some(field)) => {
|
|
||||||
let name = field.name().unwrap().to_string();
|
|
||||||
let file_name = field.file_name().unwrap().to_string();
|
|
||||||
let content_type = field.content_type().unwrap().to_string();
|
|
||||||
let data = field.bytes().await.unwrap();
|
|
||||||
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.file_type) {
|
|
||||||
response.message = format!("CoverArt file type not supported: {file_type:?}");
|
|
||||||
(
|
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
axum::Json(response),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {:?})",
|
|
||||||
file_name,
|
|
||||||
name,
|
|
||||||
content_type,
|
|
||||||
data.len(),
|
|
||||||
file_type
|
|
||||||
);
|
|
||||||
|
|
||||||
match repo_queue::coverart::insert(&pool, &raw_data, &file_type.file_type).await
|
|
||||||
{
|
|
||||||
Ok(id) => {
|
|
||||||
response.message = String::from("Successful");
|
|
||||||
response.data.push(id);
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)),
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Endpoint to link queued cover art
|
|
||||||
#[utoipa::path(
|
|
||||||
post,
|
|
||||||
path = super::super::endpoints::QUEUECOVERARTLINK,
|
|
||||||
request_body(
|
|
||||||
content = super::request::link::Request,
|
|
||||||
description = "Linking queued cover art to queued song",
|
|
||||||
content_type = "application/json"
|
|
||||||
),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Queued cover art linked", body = super::response::link::Response),
|
|
||||||
(status = 400, description = "Linkage failed", body = super::response::link::Response)
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub async fn link(
|
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
|
||||||
axum::Json(payload): axum::Json<super::request::link::Request>,
|
|
||||||
) -> (
|
|
||||||
axum::http::StatusCode,
|
|
||||||
axum::Json<super::response::link::Response>,
|
|
||||||
) {
|
|
||||||
let mut response = super::response::link::Response::default();
|
|
||||||
let id = payload.coverart_id;
|
|
||||||
let song_id = payload.song_queue_id;
|
|
||||||
|
|
||||||
match repo_queue::coverart::update(&pool, &id, &song_id).await {
|
|
||||||
Ok(_o) => {
|
|
||||||
response.data.push(super::response::link::Id {
|
|
||||||
song_queue_id: song_id,
|
|
||||||
coverart_id: id,
|
|
||||||
});
|
|
||||||
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Endpoint to fetch cover art details
|
|
||||||
#[utoipa::path(
|
|
||||||
get,
|
|
||||||
path = super::super::endpoints::QUEUECOVERART,
|
|
||||||
params(
|
|
||||||
("id" = uuid::Uuid, Path, description = "Queued cover art Id"),
|
|
||||||
("song_queue_id" = uuid::Uuid, Path, description = "Queued song Id")
|
|
||||||
),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Queued song linked", body = super::response::fetch_coverart_no_data::Response),
|
|
||||||
(status = 400, description = "Linkage failed", body = super::response::fetch_coverart_no_data::Response)
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub async fn fetch_coverart_no_data(
|
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
|
||||||
axum::extract::Query(params): axum::extract::Query<
|
|
||||||
super::request::fetch_coverart_no_data::Params,
|
|
||||||
>,
|
|
||||||
) -> (
|
|
||||||
axum::http::StatusCode,
|
|
||||||
axum::Json<super::response::fetch_coverart_no_data::Response>,
|
|
||||||
) {
|
|
||||||
let mut response = super::response::fetch_coverart_no_data::Response::default();
|
|
||||||
|
|
||||||
match params.id {
|
|
||||||
Some(id) => match repo_queue::coverart::get_coverart_queue_with_id(&pool, &id).await {
|
|
||||||
Ok(cover_art_queue) => {
|
|
||||||
response.message = String::from("Successful");
|
|
||||||
response.data.push(cover_art_queue);
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => match params.song_queue_id {
|
|
||||||
Some(song_queue_id) => {
|
|
||||||
match repo_queue::coverart::get_coverart_queue_with_song_queue_id(
|
|
||||||
&pool,
|
|
||||||
&song_queue_id,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(cover_art_queue) => {
|
|
||||||
response.message = String::from("Successful");
|
|
||||||
response.data.push(cover_art_queue);
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
response.message = String::from("No valid id provided");
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Endpoint to fetch the queued cover art data
|
|
||||||
#[utoipa::path(
|
|
||||||
get,
|
|
||||||
path = super::super::endpoints::QUEUECOVERARTDATA,
|
|
||||||
params(("id" = uuid::Uuid, Path, description = "Queued cover art Id")),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Queued cover art data", body = Vec<u8>),
|
|
||||||
(status = 400, description = "Error fetching queued cover art data", body = Vec<u8>)
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub async fn fetch_coverart_with_data(
|
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
|
||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
|
||||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
|
||||||
match repo_queue::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
|
|
||||||
Ok(data) => {
|
|
||||||
let bytes = axum::body::Bytes::from(data);
|
|
||||||
let mut response = bytes.into_response();
|
|
||||||
let headers = response.headers_mut();
|
|
||||||
// TODO: Address this hard coding for the coverart content type
|
|
||||||
headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap());
|
|
||||||
// TODO: Make the conent disposition more dynamic
|
|
||||||
headers.insert(
|
|
||||||
axum::http::header::CONTENT_DISPOSITION,
|
|
||||||
format!("attachment; filename=\"{id}.jpg\"")
|
|
||||||
.parse()
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
(axum::http::StatusCode::OK, response)
|
|
||||||
}
|
|
||||||
Err(_err) => (
|
|
||||||
axum::http::StatusCode::BAD_REQUEST,
|
|
||||||
axum::response::Response::default(),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Endpoint to create cover art
|
/// Endpoint to create cover art
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
@@ -455,52 +120,6 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Endpoint to wipe data from the cover art queue
|
|
||||||
#[utoipa::path(
|
|
||||||
patch,
|
|
||||||
path = super::super::endpoints::QUEUECOVERARTDATAWIPE,
|
|
||||||
request_body(
|
|
||||||
content = super::request::wipe_data_from_coverart_queue::Request,
|
|
||||||
description = "Data required to wipe the data from the cover art queue",
|
|
||||||
content_type = "application/json"
|
|
||||||
),
|
|
||||||
responses(
|
|
||||||
(status = 200, description = "Data wiped from cover art queue", body = super::response::wipe_data_from_coverart_queue::Response),
|
|
||||||
(status = 400, description = "Error wiping the data", body = super::response::wipe_data_from_coverart_queue::Response),
|
|
||||||
(status = 404, description = "Cover art not found", body = super::response::wipe_data_from_coverart_queue::Response)
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
pub async fn wipe_data_from_coverart_queue(
|
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
|
||||||
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,
|
|
||||||
) -> (
|
|
||||||
axum::http::StatusCode,
|
|
||||||
axum::Json<super::response::wipe_data_from_coverart_queue::Response>,
|
|
||||||
) {
|
|
||||||
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
|
||||||
let coverart_queue_id = payload.coverart_queue_id;
|
|
||||||
|
|
||||||
match repo_queue::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
|
|
||||||
Ok(coverart_queue) => {
|
|
||||||
match repo_queue::coverart::wipe_data(&pool, &coverart_queue.id).await {
|
|
||||||
Ok(id) => {
|
|
||||||
response.message = String::from("Success");
|
|
||||||
response.data.push(id);
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Endpoint to get cover art with criteria
|
/// Endpoint to get cover art with criteria
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get,
|
get,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod coverart;
|
pub mod coverart;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
|
pub mod queue;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
|
|
||||||
pub mod endpoints {
|
pub mod endpoints {
|
||||||
|
|||||||
@@ -0,0 +1,388 @@
|
|||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct CoverArtQueue {
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
pub file_type: String,
|
||||||
|
pub song_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod request {
|
||||||
|
pub mod queue {
|
||||||
|
#[derive(utoipa::ToSchema)]
|
||||||
|
pub struct Request {
|
||||||
|
/// Filename
|
||||||
|
pub file: String,
|
||||||
|
#[schema(rename = "type")]
|
||||||
|
/// File type. Should be a file and not a value
|
||||||
|
pub file_type: String,
|
||||||
|
/// Raw data of the cover art file
|
||||||
|
pub value: Vec<u8>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod link {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Request {
|
||||||
|
pub coverart_id: uuid::Uuid,
|
||||||
|
pub song_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod fetch_coverart_no_data {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Params {
|
||||||
|
pub id: Option<uuid::Uuid>,
|
||||||
|
pub song_queue_id: Option<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod fetch_coverart_with_data {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Params {
|
||||||
|
pub id: Option<uuid::Uuid>,
|
||||||
|
pub song_queue_id: Option<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod wipe_data_from_coverart_queue {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Request {
|
||||||
|
pub coverart_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
pub mod queue {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod link {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Id {
|
||||||
|
pub coverart_id: uuid::Uuid,
|
||||||
|
pub song_queue_id: uuid::Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<Id>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod fetch_coverart_no_data {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<super::super::CoverArtQueue>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod fetch_coverart_with_data {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<Vec<u8>>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod wipe_data_from_coverart_queue {
|
||||||
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod helper {
|
||||||
|
pub fn is_coverart_file_type_valid(file_type: &String) -> bool {
|
||||||
|
let valid_file_types = vec![
|
||||||
|
String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE),
|
||||||
|
String::from(icarus_meta::detection::coverart::constants::JPG_TYPE),
|
||||||
|
String::from(icarus_meta::detection::coverart::constants::PNG_TYPE),
|
||||||
|
];
|
||||||
|
|
||||||
|
for valid_file_type in valid_file_types {
|
||||||
|
if valid_file_type == *file_type {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod endpoint {
|
||||||
|
use axum::response::IntoResponse;
|
||||||
|
|
||||||
|
use crate::repo::queue as repo;
|
||||||
|
|
||||||
|
/// Endpoint to queue cover art
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = super::super::super::endpoints::QUEUECOVERART,
|
||||||
|
request_body(
|
||||||
|
content = super::request::queue::Request,
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Successful", body = super::response::queue::Response),
|
||||||
|
(status = 400, description = "Error queueing cover art", body = super::response::queue::Response)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn queue(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
mut multipart: axum::extract::Multipart,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::queue::Response>,
|
||||||
|
) {
|
||||||
|
let mut response = super::response::queue::Response::default();
|
||||||
|
|
||||||
|
match multipart.next_field().await {
|
||||||
|
Ok(Some(field)) => {
|
||||||
|
let name = field.name().unwrap().to_string();
|
||||||
|
let file_name = field.file_name().unwrap().to_string();
|
||||||
|
let content_type = field.content_type().unwrap().to_string();
|
||||||
|
let data = field.bytes().await.unwrap();
|
||||||
|
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.file_type) {
|
||||||
|
response.message = format!("CoverArt file type not supported: {file_type:?}");
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {:?})",
|
||||||
|
file_name,
|
||||||
|
name,
|
||||||
|
content_type,
|
||||||
|
data.len(),
|
||||||
|
file_type
|
||||||
|
);
|
||||||
|
|
||||||
|
match repo::coverart::insert(&pool, &raw_data, &file_type.file_type).await {
|
||||||
|
Ok(id) => {
|
||||||
|
response.message = String::from("Successful");
|
||||||
|
response.data.push(id);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)),
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint to link queued cover art
|
||||||
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = super::super::super::endpoints::QUEUECOVERARTLINK,
|
||||||
|
request_body(
|
||||||
|
content = super::request::link::Request,
|
||||||
|
description = "Linking queued cover art to queued song",
|
||||||
|
content_type = "application/json"
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Queued cover art linked", body = super::response::link::Response),
|
||||||
|
(status = 400, description = "Linkage failed", body = super::response::link::Response)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn link(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::Json(payload): axum::Json<super::request::link::Request>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::link::Response>,
|
||||||
|
) {
|
||||||
|
let mut response = super::response::link::Response::default();
|
||||||
|
let id = payload.coverart_id;
|
||||||
|
let song_id = payload.song_queue_id;
|
||||||
|
|
||||||
|
match repo::coverart::update(&pool, &id, &song_id).await {
|
||||||
|
Ok(_o) => {
|
||||||
|
response.data.push(super::response::link::Id {
|
||||||
|
song_queue_id: song_id,
|
||||||
|
coverart_id: id,
|
||||||
|
});
|
||||||
|
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint to fetch cover art details
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = super::super::super::endpoints::QUEUECOVERART,
|
||||||
|
params(
|
||||||
|
("id" = uuid::Uuid, Path, description = "Queued cover art Id"),
|
||||||
|
("song_queue_id" = uuid::Uuid, Path, description = "Queued song Id")
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Queued song linked", body = super::response::fetch_coverart_no_data::Response),
|
||||||
|
(status = 400, description = "Linkage failed", body = super::response::fetch_coverart_no_data::Response)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn fetch_coverart_no_data(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::extract::Query(params): axum::extract::Query<
|
||||||
|
super::request::fetch_coverart_no_data::Params,
|
||||||
|
>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::fetch_coverart_no_data::Response>,
|
||||||
|
) {
|
||||||
|
let mut response = super::response::fetch_coverart_no_data::Response::default();
|
||||||
|
|
||||||
|
match params.id {
|
||||||
|
Some(id) => match repo::coverart::get_coverart_queue_with_id(&pool, &id).await {
|
||||||
|
Ok(cover_art_queue) => {
|
||||||
|
response.message = String::from("Successful");
|
||||||
|
response.data.push(cover_art_queue);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => match params.song_queue_id {
|
||||||
|
Some(song_queue_id) => match repo::coverart::get_coverart_queue_with_song_queue_id(
|
||||||
|
&pool,
|
||||||
|
&song_queue_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(cover_art_queue) => {
|
||||||
|
response.message = String::from("Successful");
|
||||||
|
response.data.push(cover_art_queue);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
response.message = String::from("No valid id provided");
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint to fetch the queued cover art data
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = super::super::super::endpoints::QUEUECOVERARTDATA,
|
||||||
|
params(("id" = uuid::Uuid, Path, description = "Queued cover art Id")),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Queued cover art data", body = Vec<u8>),
|
||||||
|
(status = 400, description = "Error fetching queued cover art data", body = Vec<u8>)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn fetch_coverart_with_data(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
|
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||||
|
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
|
||||||
|
Ok(data) => {
|
||||||
|
let bytes = axum::body::Bytes::from(data);
|
||||||
|
let mut response = bytes.into_response();
|
||||||
|
let headers = response.headers_mut();
|
||||||
|
// TODO: Address this hard coding for the coverart content type
|
||||||
|
headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap());
|
||||||
|
// TODO: Make the conent disposition more dynamic
|
||||||
|
headers.insert(
|
||||||
|
axum::http::header::CONTENT_DISPOSITION,
|
||||||
|
format!("attachment; filename=\"{id}.jpg\"")
|
||||||
|
.parse()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
(axum::http::StatusCode::OK, response)
|
||||||
|
}
|
||||||
|
Err(_err) => (
|
||||||
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
|
axum::response::Response::default(),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Endpoint to wipe data from the cover art queue
|
||||||
|
#[utoipa::path(
|
||||||
|
patch,
|
||||||
|
path = super::super::super::endpoints::QUEUECOVERARTDATAWIPE,
|
||||||
|
request_body(
|
||||||
|
content = super::request::wipe_data_from_coverart_queue::Request,
|
||||||
|
description = "Data required to wipe the data from the cover art queue",
|
||||||
|
content_type = "application/json"
|
||||||
|
),
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Data wiped from cover art queue", body = super::response::wipe_data_from_coverart_queue::Response),
|
||||||
|
(status = 400, description = "Error wiping the data", body = super::response::wipe_data_from_coverart_queue::Response),
|
||||||
|
(status = 404, description = "Cover art not found", body = super::response::wipe_data_from_coverart_queue::Response)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn wipe_data_from_coverart_queue(
|
||||||
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
|
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,
|
||||||
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::wipe_data_from_coverart_queue::Response>,
|
||||||
|
) {
|
||||||
|
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
||||||
|
let coverart_queue_id = payload.coverart_queue_id;
|
||||||
|
|
||||||
|
match repo::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
|
||||||
|
Ok(coverart_queue) => {
|
||||||
|
match repo::coverart::wipe_data(&pool, &coverart_queue.id).await {
|
||||||
|
Ok(id) => {
|
||||||
|
response.message = String::from("Success");
|
||||||
|
response.data.push(id);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod coverart;
|
||||||
+53
-40
@@ -54,9 +54,12 @@ pub mod init {
|
|||||||
|
|
||||||
use crate::callers::coverart as coverart_caller;
|
use crate::callers::coverart as coverart_caller;
|
||||||
use crate::callers::metadata as metadata_caller;
|
use crate::callers::metadata as metadata_caller;
|
||||||
|
use crate::callers::queue::coverart as coverart_queue_callers;
|
||||||
use crate::callers::song as song_caller;
|
use crate::callers::song as song_caller;
|
||||||
use coverart_caller::endpoint as coverart_endpoints;
|
use coverart_caller::endpoint as coverart_endpoints;
|
||||||
use coverart_caller::response as coverart_responses;
|
use coverart_caller::response as coverart_responses;
|
||||||
|
use coverart_queue_callers::endpoint as coverart_queue_endpoints;
|
||||||
|
use coverart_queue_callers::response as coverart_queue_responses;
|
||||||
use metadata_caller::endpoint as metadata_endpoints;
|
use metadata_caller::endpoint as metadata_endpoints;
|
||||||
use metadata_caller::response as metadata_responses;
|
use metadata_caller::response as metadata_responses;
|
||||||
use song_caller::endpoint as song_endpoints;
|
use song_caller::endpoint as song_endpoints;
|
||||||
@@ -114,16 +117,16 @@ pub mod init {
|
|||||||
#[openapi(
|
#[openapi(
|
||||||
paths(song_endpoints::queue_song, song_endpoints::link_user_id, song_endpoints::fetch_queue_song, song_endpoints::download_flac,
|
paths(song_endpoints::queue_song, song_endpoints::link_user_id, song_endpoints::fetch_queue_song, song_endpoints::download_flac,
|
||||||
song_endpoints::update_song_queue_status, song_endpoints::update_song_queue, song_endpoints::create_metadata, song_endpoints::wipe_data_from_song_queue, song_endpoints::get_songs, song_endpoints::get_all_songs, song_endpoints::stream_song, song_endpoints::download_song,
|
song_endpoints::update_song_queue_status, song_endpoints::update_song_queue, song_endpoints::create_metadata, song_endpoints::wipe_data_from_song_queue, song_endpoints::get_songs, song_endpoints::get_all_songs, song_endpoints::stream_song, song_endpoints::download_song,
|
||||||
song_endpoints::delete_song, coverart_endpoints::queue, coverart_endpoints::link, coverart_endpoints::fetch_coverart_no_data,
|
song_endpoints::delete_song, coverart_queue_endpoints::queue, coverart_queue_endpoints::link, coverart_queue_endpoints::fetch_coverart_no_data,
|
||||||
coverart_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_endpoints::wipe_data_from_coverart_queue,
|
coverart_queue_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_queue_endpoints::wipe_data_from_coverart_queue,
|
||||||
coverart_endpoints::get_coverart, coverart_endpoints::download_coverart,
|
coverart_endpoints::get_coverart, coverart_endpoints::download_coverart,
|
||||||
metadata_endpoints::queue_metadata, metadata_endpoints::fetch_metadata),
|
metadata_endpoints::queue_metadata, metadata_endpoints::fetch_metadata),
|
||||||
components(schemas(song_responses::Response, song_responses::link_user_id::Response, song_responses::fetch_queue_song::Response,
|
components(schemas(song_responses::Response, song_responses::link_user_id::Response, song_responses::fetch_queue_song::Response,
|
||||||
song_responses::update_status::Response, song_responses::update_song_queue::Response, song_responses::create_metadata::Response,
|
song_responses::update_status::Response, song_responses::update_song_queue::Response, song_responses::create_metadata::Response,
|
||||||
song_responses::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response,
|
song_responses::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response,
|
||||||
coverart_responses::Response, coverart_responses::link::Response, coverart_responses::fetch_coverart_no_data::Response,
|
coverart_queue_responses::queue::Response, coverart_queue_responses::link::Response, coverart_queue_responses::fetch_coverart_no_data::Response,
|
||||||
coverart_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response,
|
coverart_queue_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response,
|
||||||
coverart_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
|
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
|
||||||
metadata_responses::queue_metadata::Response, metadata_responses::fetch_metadata::Response)),
|
metadata_responses::queue_metadata::Response, metadata_responses::fetch_metadata::Response)),
|
||||||
tags(
|
tags(
|
||||||
(name = "Icarus API", description = "Web API to manage music")
|
(name = "Icarus API", description = "Web API to manage music")
|
||||||
@@ -190,31 +193,32 @@ pub mod init {
|
|||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUECOVERART,
|
crate::callers::endpoints::QUEUECOVERART,
|
||||||
post(crate::callers::coverart::endpoint::queue).route_layer(
|
post(crate::callers::queue::coverart::endpoint::queue).route_layer(
|
||||||
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUECOVERARTDATA,
|
crate::callers::endpoints::QUEUECOVERARTDATA,
|
||||||
get(crate::callers::coverart::endpoint::fetch_coverart_with_data).route_layer(
|
get(crate::callers::queue::coverart::endpoint::fetch_coverart_with_data)
|
||||||
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
.route_layer(axum::middleware::from_fn(
|
||||||
),
|
crate::auth::auth::<axum::body::Body>,
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUECOVERART,
|
crate::callers::endpoints::QUEUECOVERART,
|
||||||
get(crate::callers::coverart::endpoint::fetch_coverart_no_data).route_layer(
|
get(crate::callers::queue::coverart::endpoint::fetch_coverart_no_data).route_layer(
|
||||||
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUECOVERARTLINK,
|
crate::callers::endpoints::QUEUECOVERARTLINK,
|
||||||
patch(crate::callers::coverart::endpoint::link).route_layer(
|
patch(crate::callers::queue::coverart::endpoint::link).route_layer(
|
||||||
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUECOVERARTDATAWIPE,
|
crate::callers::endpoints::QUEUECOVERARTDATAWIPE,
|
||||||
patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue)
|
patch(crate::callers::queue::coverart::endpoint::wipe_data_from_coverart_queue)
|
||||||
.route_layer(axum::middleware::from_fn(
|
.route_layer(axum::middleware::from_fn(
|
||||||
crate::auth::auth::<axum::body::Body>,
|
crate::auth::auth::<axum::body::Body>,
|
||||||
)),
|
)),
|
||||||
@@ -743,11 +747,10 @@ mod tests {
|
|||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
match super::upload_coverart_queue_req(&app).await {
|
match super::upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = super::get_resp_data::<
|
||||||
super::get_resp_data::<crate::callers::coverart::response::Response>(
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
response,
|
>(response)
|
||||||
)
|
.await;
|
||||||
.await;
|
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let coverart_id = resp.data[0];
|
let coverart_id = resp.data[0];
|
||||||
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
||||||
@@ -761,7 +764,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = super::get_resp_data::<
|
let resp = super::get_resp_data::<
|
||||||
crate::callers::coverart::response::link::Response,
|
crate::callers::queue::coverart::response::link::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1023,7 +1026,7 @@ mod tests {
|
|||||||
match sequence_flow::queue_song_and_coverart_flow(&app).await {
|
match sequence_flow::queue_song_and_coverart_flow(&app).await {
|
||||||
Ok((resp_one, song_queue_id)) => {
|
Ok((resp_one, song_queue_id)) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::queue::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(resp_one)
|
>(resp_one)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1256,7 +1259,7 @@ mod tests {
|
|||||||
match sequence_flow::queue_song_and_coverart_flow(&app).await {
|
match sequence_flow::queue_song_and_coverart_flow(&app).await {
|
||||||
Ok((resp_one, song_queue_id)) => {
|
Ok((resp_one, song_queue_id)) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::queue::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(resp_one)
|
>(resp_one)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1396,8 +1399,10 @@ mod tests {
|
|||||||
// Send request
|
// Send request
|
||||||
match upload_coverart_queue_req(&app).await {
|
match upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let id = resp.data[0];
|
let id = resp.data[0];
|
||||||
assert_eq!(false, id.is_nil(), "Should not be empty");
|
assert_eq!(false, id.is_nil(), "Should not be empty");
|
||||||
@@ -1431,8 +1436,10 @@ mod tests {
|
|||||||
|
|
||||||
match song_queue_req(&app).await {
|
match song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let song_queue_id = resp.data[0];
|
let song_queue_id = resp.data[0];
|
||||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||||
@@ -1440,9 +1447,10 @@ mod tests {
|
|||||||
// Send request
|
// Send request
|
||||||
match upload_coverart_queue_req(&app).await {
|
match upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response)
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
.await;
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let coverart_id = resp.data[0];
|
let coverart_id = resp.data[0];
|
||||||
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
||||||
@@ -1452,7 +1460,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::link::Response,
|
crate::callers::queue::coverart::response::link::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1505,8 +1513,10 @@ mod tests {
|
|||||||
|
|
||||||
match song_queue_req(&app).await {
|
match song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let song_queue_id = resp.data[0];
|
let song_queue_id = resp.data[0];
|
||||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||||
@@ -1514,7 +1524,7 @@ mod tests {
|
|||||||
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::queue::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1553,8 +1563,10 @@ mod tests {
|
|||||||
|
|
||||||
match song_queue_req(&app).await {
|
match song_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response).await;
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let song_queue_id = resp.data[0];
|
let song_queue_id = resp.data[0];
|
||||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||||
@@ -1562,9 +1574,10 @@ mod tests {
|
|||||||
// Send request
|
// Send request
|
||||||
match upload_coverart_queue_req(&app).await {
|
match upload_coverart_queue_req(&app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp =
|
let resp = get_resp_data::<
|
||||||
get_resp_data::<crate::callers::coverart::response::Response>(response)
|
crate::callers::queue::coverart::response::queue::Response,
|
||||||
.await;
|
>(response)
|
||||||
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let coverart_id = resp.data[0];
|
let coverart_id = resp.data[0];
|
||||||
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
assert_eq!(false, coverart_id.is_nil(), "Should not be empty");
|
||||||
@@ -1574,7 +1587,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::link::Response,
|
crate::callers::queue::coverart::response::link::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1774,7 +1787,7 @@ mod tests {
|
|||||||
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::queue::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -1975,7 +1988,7 @@ mod tests {
|
|||||||
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::fetch_coverart_no_data::Response,
|
crate::callers::queue::coverart::response::fetch_coverart_no_data::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
@@ -2007,7 +2020,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::coverart::response::wipe_data_from_coverart_queue::Response,
|
crate::callers::queue::coverart::response::wipe_data_from_coverart_queue::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ pub async fn update(
|
|||||||
pub async fn get_coverart_queue_with_id(
|
pub async fn get_coverart_queue_with_id(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<crate::callers::coverart::CoverArtQueue, sqlx::Error> {
|
) -> Result<crate::callers::queue::coverart::CoverArtQueue, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE id = $1;
|
SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE id = $1;
|
||||||
@@ -68,7 +68,7 @@ pub async fn get_coverart_queue_with_id(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(crate::callers::coverart::CoverArtQueue {
|
Ok(row) => Ok(crate::callers::queue::coverart::CoverArtQueue {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -89,7 +89,7 @@ pub async fn get_coverart_queue_with_id(
|
|||||||
pub async fn get_coverart_queue_with_song_queue_id(
|
pub async fn get_coverart_queue_with_song_queue_id(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<crate::callers::coverart::CoverArtQueue, sqlx::Error> {
|
) -> Result<crate::callers::queue::coverart::CoverArtQueue, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE song_queue_id = $1;
|
SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE song_queue_id = $1;
|
||||||
@@ -103,7 +103,7 @@ pub async fn get_coverart_queue_with_song_queue_id(
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(crate::callers::coverart::CoverArtQueue {
|
Ok(row) => Ok(crate::callers::queue::coverart::CoverArtQueue {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
|||||||
Reference in New Issue
Block a user