@@ -178,14 +178,64 @@ pub mod endpoint {
|
|||||||
file_type
|
file_type
|
||||||
);
|
);
|
||||||
|
|
||||||
match repo::coverart::insert(&pool, &raw_data, &file_type.file_type).await {
|
let lab_config = crate::util::maze::get_config();
|
||||||
Ok(id) => {
|
|
||||||
response.message = String::from("Successful");
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
response.data.push(id);
|
let data = labyrinth::Data {
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
raw_data: raw_data,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let filename = simodels::coverart::generate_filename(
|
||||||
|
simodels::types::CoverArtType::JpegExtension,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let file_path = format!("queued/coverart/{filename}");
|
||||||
|
|
||||||
|
println!("Key: {file_path:?}");
|
||||||
|
|
||||||
|
match lr.upload(&file_path, &data).await {
|
||||||
|
Ok(_res) => {
|
||||||
|
match repo::coverart::insert(
|
||||||
|
&pool,
|
||||||
|
&data.raw_data,
|
||||||
|
&file_type.file_type,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(id) => {
|
||||||
|
match repo::data::insert(
|
||||||
|
&pool,
|
||||||
|
&file_path,
|
||||||
|
&lr.config.bucket,
|
||||||
|
&lr.config.region,
|
||||||
|
&id,
|
||||||
|
)
|
||||||
|
.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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
eprintln!("Error: {err:?}");
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,3 +96,106 @@ pub async fn get_with_song_queue_id(
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod queue {
|
||||||
|
pub mod coverart {
|
||||||
|
use sqlx::Row;
|
||||||
|
|
||||||
|
pub async fn insert(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
file_key: &str,
|
||||||
|
bucket: &str,
|
||||||
|
region: &str,
|
||||||
|
coverart_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
INSERT INTO "coverartQueueData" (file_key, bucket, region, coverart_queue_id) VALUES($1, $2, $3, $4) RETURNING id;
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(file_key)
|
||||||
|
.bind(bucket)
|
||||||
|
.bind(region)
|
||||||
|
.bind(coverart_queue_id)
|
||||||
|
.fetch_one(pool).await {
|
||||||
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
Err(_err) => Err(sqlx::Error::RowNotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_file_key(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
file_key: &str,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
UPDATE "coverartQueueData" SET file_key = $1 WHERE id = $2;
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(file_key)
|
||||||
|
.bind(id)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_row) => Ok(()),
|
||||||
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<(uuid::Uuid, String, String, String, uuid::Uuid), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, file_key, bucket, region, coverart_queue_id FROM "coverartQueueData"
|
||||||
|
WHERE id = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(id)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
let file_key: String = row.try_get("file_key")?;
|
||||||
|
let bucket: String = row.try_get("bucket")?;
|
||||||
|
let region: String = row.try_get("region")?;
|
||||||
|
let coverart_queue_id: uuid::Uuid = row.try_get("coverart_queue_id")?;
|
||||||
|
|
||||||
|
Ok((*id, file_key, bucket, region, coverart_queue_id))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_with_coverart_queue_id(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
coverart_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<(uuid::Uuid, String, String, String, uuid::Uuid), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, file_key, bucket, region, coverart_queue_id FROM "coverartQueueData"
|
||||||
|
WHERE coverart_queue_id = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(coverart_queue_id)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
|
let file_key: String = row.try_get("file_key")?;
|
||||||
|
let bucket: String = row.try_get("bucket")?;
|
||||||
|
let region: String = row.try_get("region")?;
|
||||||
|
|
||||||
|
Ok((id, file_key, bucket, region, *coverart_queue_id))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user