Compare commits

..
4 Commits
Author SHA1 Message Date
phoenix 718cdb617d S3 coverart (#261)
soaricarus_api CI / Check (push) Successful in 6m37s
soaricarus_api CI / Rustfmt (push) Successful in 4m19s
soaricarus_api CI / Clippy (push) Successful in 6m57s
soaricarus_api CI / build (push) Successful in 6m58s
soaricarus_api CI / Test Suite (push) Successful in 3m37s
Reviewed-on: #261
2026-08-15 12:30:44 -04:00
phoenix ff3567f8ef S3 song download (#260)
soaricarus_api CI / Rustfmt (push) Successful in 3m46s
soaricarus_api CI / Check (push) Successful in 5m3s
soaricarus_api CI / Test Suite (push) Successful in 6m21s
soaricarus_api CI / Clippy (push) Successful in 6m46s
soaricarus_api CI / build (push) Successful in 8m45s
pr CI / Test Suite (pull_request) Successful in 5m9s
Reviewed-on: #260
2026-08-14 16:41:56 -04:00
phoenix 695faf7502 Coverart queue (#259)
pr CI / Test Suite (pull_request) Failing after 2m42s
soaricarus_api CI / Check (push) Successful in 7m15s
soaricarus_api CI / Rustfmt (push) Successful in 5m25s
soaricarus_api CI / Clippy (push) Failing after 7m1s
soaricarus_api CI / build (push) Successful in 7m47s
soaricarus_api CI / Test Suite (push) Failing after 2m24s
Reviewed-on: #259
2026-08-14 08:42:38 -04:00
phoenix bf88f249ea Song queue (#258)
soaricarus_api CI / Check (push) Successful in 3m59s
soaricarus_api CI / build (push) Successful in 5m6s
soaricarus_api CI / Rustfmt (push) Successful in 5m27s
soaricarus_api CI / Test Suite (push) Successful in 5m50s
soaricarus_api CI / Clippy (push) Successful in 6m26s
Reviewed-on: #258
2026-08-13 15:27:31 -04:00
16 changed files with 892 additions and 547 deletions
Generated
+250 -237
View File
File diff suppressed because it is too large Load Diff
+12 -12
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "soaricarus_api" name = "soaricarus_api"
version = "0.5.3" version = "0.5.7"
edition = "2024" edition = "2024"
rust-version = "1.95" rust-version = "1.95"
license = "MIT" license = "MIT"
@@ -10,26 +10,26 @@ description = "Core API for interacting with soaricarus"
axum = { version = "0.8.9", features = ["multipart"] } axum = { version = "0.8.9", features = ["multipart"] }
axum-extra = { version = "0.12.6", features = ["cookie"] } axum-extra = { version = "0.12.6", features = ["cookie"] }
openssl = { version = "0.10.81", features = ["vendored"] } openssl = { version = "0.10.81", features = ["vendored"] }
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.229", features = ["derive"] }
serde_json = { version = "1.0.150" } serde_json = { version = "1.0.151" }
tokio = { version = "1.52.3", features = ["full"] } tokio = { version = "1.53.1", features = ["full"] }
tokio-util = { version = "0.7.18", features = ["io"] } tokio-util = { version = "0.7.19", features = ["io"] }
tower = { version = "0.5.3", features = ["full"] } tower = { version = "0.5.3", features = ["full"] }
tower-http = { version = "0.7.0", features = ["cors", "timeout"] } tower-http = { version = "0.7.0", features = ["cors", "timeout"] }
tracing-subscriber = "0.3.23" tracing-subscriber = "0.3.23"
futures = { version = "0.3.32" } futures = { version = "0.3.34" }
mime_guess = { version = "2.0.5" } mime_guess = { version = "2.0.5" }
uuid = { version = "1.23.5", features = ["v4", "serde"] } uuid = { version = "1.24.1", features = ["v4", "serde"] }
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] } time = { version = "0.3.55", features = ["formatting", "macros", "parsing", "serde"] }
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] } jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa = { version = "5.5.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" } simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.2" }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" } simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.5-main-94d97cb81d-111" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" } sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.1" }
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.4" } labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.5" }
[dev-dependencies] [dev-dependencies]
common-multipart-rfc7578 = { version = "0.7.0" } common-multipart-rfc7578 = { version = "0.7.0" }
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2025 Kun Deng Copyright (c) 2026 Kun Deng
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+10 -1
View File
@@ -28,11 +28,18 @@ CREATE TABLE IF NOT EXISTS "metadataQueue" (
-- Table to store queued coverart -- Table to store queued coverart
CREATE TABLE IF NOT EXISTS "coverartQueue" ( CREATE TABLE IF NOT EXISTS "coverartQueue" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
data BYTEA NULL,
file_type TEXT NOT NULL, file_type TEXT NOT NULL,
song_queue_id UUID NULL song_queue_id UUID NULL
); );
CREATE TABLE IF NOT EXISTS "coverartQueueData" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
file_key TEXT NOT NULL,
bucket TEXT NOT NULL,
region TEXT NOT NULL,
coverart_queue_id UUID NOT NULL
);
-- Create an index for better query performance -- Create an index for better query performance
CREATE INDEX metadata_queue_data_metadata ON "metadataQueue" USING gin (metadata); CREATE INDEX metadata_queue_data_metadata ON "metadataQueue" USING gin (metadata);
@@ -56,6 +63,7 @@ CREATE TABLE IF NOT EXISTS "song" (
date_created timestamptz DEFAULT now(), date_created timestamptz DEFAULT now(),
filename TEXT NOT NULL, filename TEXT NOT NULL,
directory TEXT NOT NULL, directory TEXT NOT NULL,
file_key TEXT NOT NULL,
user_id UUID NULL user_id UUID NULL
-- TODO: Add coverart id later. This will allow multiple songs to be linked to a single cover art -- TODO: Add coverart id later. This will allow multiple songs to be linked to a single cover art
); );
@@ -66,5 +74,6 @@ CREATE TABLE IF NOT EXISTS "coverart" (
directory TEXT NOT NULL, directory TEXT NOT NULL,
filename TEXT NOT NULL, filename TEXT NOT NULL,
file_type TEXT NOT NULL, file_type TEXT NOT NULL,
file_key TEXT NOT NULL,
song_id UUID NOT NULL song_id UUID NOT NULL
); );
+55 -17
View File
@@ -63,14 +63,16 @@ pub mod endpoint {
let mut response = super::response::create_coverart::Response::default(); let mut response = super::response::create_coverart::Response::default();
let id = payload.coverart_queue_id; let id = payload.coverart_queue_id;
match repo_queue::coverart::get_coverart_queue_data_with_id(&pool, &id).await { match repo_queue::data::queue::coverart::get_with_coverart_queue_id(&pool, &id).await {
Ok((_id, file_key, _bucket, _region, _)) => {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match lr.download(&file_key).await {
Ok(data) => { Ok(data) => {
let song_id = payload.song_id;
match crate::repo::song::get_song(&pool, &song_id).await {
Ok(song) => {
let directory = sienvy::environment::get_root_directory().value;
let file_type = let file_type =
simeta::detection::coverart::file_type_from_data(&data).unwrap(); simeta::detection::coverart::file_type_from_data(&data).unwrap();
let coverart_type = if file_type.file_type let coverart_type = if file_type.file_type
== simeta::detection::coverart::constants::JPEG_TYPE == simeta::detection::coverart::constants::JPEG_TYPE
{ {
@@ -93,18 +95,45 @@ pub mod endpoint {
let filename = let filename =
simodels::coverart::generate_filename(coverart_type, true).unwrap(); simodels::coverart::generate_filename(coverart_type, true).unwrap();
let mut coverart = simodels::coverart::init::init_coverart_dir_and_filename( let data = labyrinth::Data {
raw_data: data,
..Default::default()
};
let new_file_key = format!("processed/coverart/{filename}");
match lr.upload(&new_file_key, &data).await {
Ok(_resp) => {
// TODO: Change it to the s3 bucket
let directory = sienvy::environment::get_root_directory().value;
let mut coverart =
simodels::coverart::init::init_coverart_dir_and_filename(
&directory, &filename, &directory, &filename,
); );
let song = match crate::repo::song::get_song(
&pool,
&payload.song_id,
)
.await
{
Ok(song) => song,
Err(err) => {
eprintln!("Error: {err:?}");
return (
axum::http::StatusCode::BAD_REQUEST,
axum::Json(response),
);
}
};
coverart.title = song.album.clone(); coverart.title = song.album.clone();
coverart.file_type = file_type.file_type; coverart.file_type = file_type.file_type;
coverart.data = data; coverart.data = data.raw_data;
coverart.file_key = new_file_key;
match coverart.save_to_filesystem() { match repo::coverart::create(&pool, &coverart, &payload.song_id)
Ok(_) => { .await
match repo::coverart::create(&pool, &coverart, &song.id).await { {
Ok(id) => { Ok(id) => {
coverart.song_id = song_id; coverart.song_id = payload.song_id;
coverart.id = id; coverart.id = id;
println!("Cover Art created"); println!("Cover Art created");
@@ -120,7 +149,7 @@ pub mod endpoint {
} }
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); eprintln!("Error: {err:?}");
( (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response), axum::Json(response),
@@ -129,14 +158,20 @@ pub mod endpoint {
} }
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); eprintln!("Error: {err:?}");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
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::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
} }
} }
} }
@@ -197,8 +232,11 @@ pub mod endpoint {
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (axum::http::StatusCode, axum::response::Response) { ) -> (axum::http::StatusCode, axum::response::Response) {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match repo::coverart::get_coverart(&pool, &id).await { match repo::coverart::get_coverart(&pool, &id).await {
Ok(coverart) => match simodels::coverart::io::to_data(&coverart) { Ok(coverart) => match lr.download(&coverart.file_key).await {
Ok(data) => { Ok(data) => {
let (file_type, img_type) = let (file_type, img_type) =
match simeta::detection::coverart::file_type_from_data(&data) { match simeta::detection::coverart::file_type_from_data(&data) {
+110 -15
View File
@@ -178,14 +178,60 @@ 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();
let lr = labyrinth::Labyrinth { config: lab_config };
let data = labyrinth::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, &file_type.file_type).await {
Ok(id) => { Ok(id) => {
println!("Inserting queued data");
match repo::data::queue::coverart::insert(
&pool,
&file_path,
&lr.config.bucket,
&lr.config.region,
&id,
)
.await
{
Ok(_id) => {
println!("Successfully did it");
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),
)
}
}
}
Err(err) => {
response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
} }
} }
@@ -313,11 +359,19 @@ pub mod endpoint {
)] )]
pub async fn fetch_coverart_with_data( pub async fn fetch_coverart_with_data(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(coverart_queue_id): axum::extract::Path<uuid::Uuid>,
) -> (axum::http::StatusCode, axum::response::Response) { ) -> (axum::http::StatusCode, axum::response::Response) {
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await { match repo::data::queue::coverart::get_with_coverart_queue_id(&pool, &coverart_queue_id)
.await
{
Ok((_id, file_key, _bucket, _region, _)) => {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match lr.download(&file_key).await {
Ok(data) => { Ok(data) => {
let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap(); let file_type =
simeta::detection::coverart::file_type_from_data(&data).unwrap();
let bytes = axum::body::Bytes::from(data); let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response(); let mut response = bytes.into_response();
let headers = response.headers_mut(); let headers = response.headers_mut();
@@ -330,9 +384,13 @@ pub mod endpoint {
== simeta::detection::coverart::constants::JPEG_TYPE == simeta::detection::coverart::constants::JPEG_TYPE
{ {
simodels::types::CoverArtType::JpegExtension simodels::types::CoverArtType::JpegExtension
} else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE { } else if file_type.file_type
== simeta::detection::coverart::constants::JPG_TYPE
{
simodels::types::CoverArtType::JpgExtension simodels::types::CoverArtType::JpgExtension
} else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE { } else if file_type.file_type
== simeta::detection::coverart::constants::PNG_TYPE
{
simodels::types::CoverArtType::PngExtension simodels::types::CoverArtType::PngExtension
} else { } else {
return ( return (
@@ -340,7 +398,8 @@ pub mod endpoint {
axum::response::Response::default(), axum::response::Response::default(),
); );
}; };
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap(); let filename =
simodels::coverart::generate_filename(coverart_type, true).unwrap();
headers.insert( headers.insert(
axum::http::header::CONTENT_DISPOSITION, axum::http::header::CONTENT_DISPOSITION,
format!("attachment; filename=\"{filename}\"") format!("attachment; filename=\"{filename}\"")
@@ -350,10 +409,23 @@ pub mod endpoint {
(axum::http::StatusCode::OK, response) (axum::http::StatusCode::OK, response)
} }
Err(_err) => ( Err(err) => {
axum::http::StatusCode::BAD_REQUEST, eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::response::Response::default(), axum::response::Response::default(),
), )
}
}
}
Err(err) => {
eprintln!("Record not found");
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::response::Response::default(),
)
}
} }
} }
@@ -383,16 +455,39 @@ pub mod endpoint {
let coverart_queue_id = payload.coverart_queue_id; let coverart_queue_id = payload.coverart_queue_id;
match repo::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { match repo::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
Ok(coverart_queue) => { Ok(_coverart_queue) => {
match repo::coverart::wipe_data(&pool, &coverart_queue.id).await { match repo::data::queue::coverart::get_with_coverart_queue_id(
Ok(id) => { &pool,
&coverart_queue_id,
)
.await
{
Ok((_id, file_key, _bucket, _region, _)) => {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match lr.delete(&file_key).await {
Ok(_) => {
response.message = String::from("Success"); response.message = String::from("Success");
response.data.push(id); response.data.push(coverart_queue_id);
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
} }
Err(err) => {
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
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::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
} }
} }
} }
+4 -15
View File
@@ -160,7 +160,6 @@ pub mod endpoint {
match super::is_song_valid(&raw_data).await { match super::is_song_valid(&raw_data).await {
Ok(valid) => { Ok(valid) => {
if valid { if valid {
println!("Go");
match repo::song::insert( match repo::song::insert(
&pool, &pool,
&file_name, &file_name,
@@ -179,23 +178,13 @@ pub mod endpoint {
raw_data: copied_raw_data, raw_data: copied_raw_data,
..Default::default() ..Default::default()
}; };
/*
let filename = simodels::song::generate_filename(
simodels::types::MusicType::FlacExtension,
true,
)
.unwrap();
*/
println!("Filename: {file_name:?}"); println!("Filename: {file_name:?}");
let file_path = format!("queued/song/{file_name}"); let file_path = format!("queued/song/{file_name}");
println!("Path: {file_path:?}"); println!("Path: {file_path:?}");
match lr.upload(&file_path, &data).await { match lr.upload(&file_path, &data).await {
Ok(res) => { Ok(_res) => {
println!("Result: {res:?}");
println!("Saving to db");
match repo::data::insert( match repo::data::insert(
&pool, &pool,
&file_path, &file_path,
@@ -511,7 +500,7 @@ pub mod endpoint {
println!("Valid song"); println!("Valid song");
match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await { match repo::data::get_with_song_queue_id(&pool, &song_queue_id).await {
Ok((_id, file_key, _bucket, _region, _)) => { Ok((id, file_key, _bucket, _region, _)) => {
match lr.delete(&file_key).await { match lr.delete(&file_key).await {
Ok(_response) => { Ok(_response) => {
let data = labyrinth::Data { let data = labyrinth::Data {
@@ -531,7 +520,7 @@ pub mod endpoint {
Ok(_) => { Ok(_) => {
match repo::data::update_file_key( match repo::data::update_file_key(
&pool, &pool,
&song_queue_id, &id,
&new_file_key, &new_file_key,
) )
.await .await
+72 -11
View File
@@ -159,8 +159,14 @@ pub mod endpoint {
} }
} }
match song.save_to_filesystem() { song.file_key = format!("processed/song/{}", song.filename);
Ok(_) => match repo::song::insert(&pool, &song).await { let data_of_song = labyrinth::Data {
raw_data: song.data.clone(),
..Default::default()
};
match lr.upload(&song.file_key, &data_of_song).await {
Ok(_resp) => match repo::song::insert(&pool, &song).await {
Ok((date_created, id)) => { Ok((date_created, id)) => {
song.id = id; song.id = id;
song.date_created = Some(date_created); song.date_created = Some(date_created);
@@ -176,7 +182,7 @@ pub mod endpoint {
} }
}, },
Err(err) => { Err(err) => {
response.message = err.to_string(); eprintln!("Error: {err:?}");
( (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response), axum::Json(response),
@@ -290,17 +296,41 @@ pub mod endpoint {
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> impl IntoResponse { ) -> impl IntoResponse {
match repo::song::get_song(&pool, &id).await { match repo::song::get_song(&pool, &id).await {
Ok(song) => { Ok(mut song) => {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match lr.download(&song.file_key).await {
Ok(data) => {
song.filename = simodels::song::generate_filename(
simodels::types::MusicType::FlacExtension,
true,
)
.unwrap();
// TODO: At some point, directory will no longer be needed with s3
song.directory = sienvy::environment::get_root_directory().value;
song.data = data;
match song.save_to_filesystem() {
Ok(_) => {
let song_path = song.song_path().unwrap(); let song_path = song.song_path().unwrap();
let path = std::path::Path::new(&song_path); let path = std::path::Path::new(&song_path);
if !path.starts_with(&song.directory) || !path.exists() { if !path.starts_with(&song.directory) || !path.exists() {
return Err((axum::http::StatusCode::NOT_FOUND, "File not found")); return Err((
axum::http::StatusCode::NOT_FOUND,
"File not found",
));
} }
let file = match tokio::fs::File::open(&path).await { let file = match tokio::fs::File::open(&path).await {
Ok(file) => file, Ok(file) => file,
Err(_) => return Err((axum::http::StatusCode::NOT_FOUND, "File not found")), Err(_) => {
return Err((
axum::http::StatusCode::NOT_FOUND,
"File not found",
));
}
}; };
let file_size = match file.metadata().await { let file_size = match file.metadata().await {
@@ -322,8 +352,34 @@ pub mod endpoint {
.header("content-length", file_size.to_string()) .header("content-length", file_size.to_string())
.body(axum::body::Body::from_stream(stream)) .body(axum::body::Body::from_stream(stream))
.unwrap(); .unwrap();
match song.remove_from_filesystem() {
Ok(rep) Ok(_) => Ok(rep),
Err(err) => {
eprintln!("Error: {err:?}");
Err((
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
"Could not read file",
))
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
Err((
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
"Could not find file",
))
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
Err((
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
"Could not find file",
))
}
}
} }
Err(_err) => Err(( Err(_err) => Err((
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
@@ -347,8 +403,11 @@ pub mod endpoint {
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>, axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (axum::http::StatusCode, axum::response::Response) { ) -> (axum::http::StatusCode, axum::response::Response) {
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match repo::song::get_song(&pool, &id).await { match repo::song::get_song(&pool, &id).await {
Ok(song) => match simodels::song::io::to_data(&song) { Ok(song) => match lr.download(&song.file_key).await {
Ok(data) => { Ok(data) => {
let bytes = axum::body::Bytes::from(data); let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response(); let mut response = bytes.into_response();
@@ -397,6 +456,8 @@ pub mod endpoint {
axum::Json<super::response::delete_song::Response>, axum::Json<super::response::delete_song::Response>,
) { ) {
let mut response = super::response::delete_song::Response::default(); let mut response = super::response::delete_song::Response::default();
let lab_config = crate::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
match repo::song::get_song(&pool, &id).await { match repo::song::get_song(&pool, &id).await {
Ok(song) => { Ok(song) => {
@@ -420,7 +481,7 @@ pub mod endpoint {
match repo::coverart::delete_coverart(&pool, &coverart.id).await match repo::coverart::delete_coverart(&pool, &coverart.id).await
{ {
Ok(deleted_coverart) => { Ok(deleted_coverart) => {
match song.remove_from_filesystem() { match lr.delete(&song.file_key).await {
Ok(_) => match coverart.remove_from_filesystem() { Ok(_) => match coverart.remove_from_filesystem() {
Ok(_) => { Ok(_) => {
response.message = String::from( response.message = String::from(
@@ -438,7 +499,7 @@ pub mod endpoint {
} }
}, },
Err(err) => { Err(err) => {
response.message = err.to_string(); eprintln!("Error: {err:?}");
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
} }
} }
+120 -2
View File
@@ -500,10 +500,128 @@ mod tests {
} }
mod sequence_flow { mod sequence_flow {
pub const TEST_SONG_01_FILE_KEY: &str = "processed/song/track01.flac";
pub const TEST_SONG_02_FILE_KEY: &str = "processed/song/track02.flac";
pub const TEST_COVERART_01_FILE_KEY: &str = "processed/coverart/Coverart-1.jpg";
pub const TEST_COVERART_02_FILE_KEY: &str = "processed/coverart/Coverart-2.jpg";
pub struct SongBucket {
pub file_key: String,
pub path: String,
}
pub struct CoverArtBucket {
pub file_key: String,
pub path: String,
}
pub async fn upload_test_songs_to_bucket() {
let songs = vec![
SongBucket {
file_key: TEST_SONG_01_FILE_KEY.to_string(),
path: "tests/I/track01.flac".to_string(),
},
SongBucket {
file_key: TEST_SONG_02_FILE_KEY.to_string(),
path: "tests/I/track02.flac".to_string(),
},
];
let lab_config = soaricarus_api::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
for song in &songs {
let p = std::path::Path::new(&song.path);
match tokio::fs::File::open(p).await {
Ok(mut _file) => {
let data = labyrinth::Data {
filepath: song.path.clone(),
..Default::default()
};
match lr.upload(&song.file_key, &data).await {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
};
}
}
pub async fn upload_test_coverarts_to_bucket() {
let coverarts = vec![
CoverArtBucket {
file_key: TEST_COVERART_01_FILE_KEY.to_string(),
path: "tests/I/Coverart-1.jpg".to_string(),
},
CoverArtBucket {
file_key: TEST_COVERART_02_FILE_KEY.to_string(),
path: "tests/I/Coverart-2.jpg".to_string(),
},
];
let lab_config = soaricarus_api::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
for coverart in &coverarts {
let p = std::path::Path::new(&coverart.path);
match tokio::fs::File::open(p).await {
Ok(mut _file) => {
let data = labyrinth::Data {
filepath: coverart.path.clone(),
..Default::default()
};
match lr.upload(&coverart.file_key, &data).await {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
};
}
}
pub async fn delete_test_songs_from_bucket() {
let songs = vec![
SongBucket {
file_key: TEST_SONG_01_FILE_KEY.to_string(),
path: "tests/I/track01.flac".to_string(),
},
SongBucket {
file_key: TEST_SONG_02_FILE_KEY.to_string(),
path: "tests/I/track02.flac".to_string(),
},
];
let lab_config = soaricarus_api::util::maze::get_config();
let lr = labyrinth::Labyrinth { config: lab_config };
for song in &songs {
match lr.delete(&song.file_key).await {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
}
// Flow for queueing song // Flow for queueing song
pub async fn queue_song_flow( pub async fn queue_song_flow(
app: &axum::Router, app: &axum::Router,
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> { ) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
upload_test_songs_to_bucket().await;
match super::request::song_queue_req(&app).await { match super::request::song_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = super::util::get_resp_data::< let resp = super::util::get_resp_data::<
@@ -561,6 +679,7 @@ mod tests {
app: &axum::Router, app: &axum::Router,
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
) -> Result<axum::response::Response, axum::http::Error> { ) -> Result<axum::response::Response, axum::http::Error> {
upload_test_coverarts_to_bucket().await;
match super::request::upload_coverart_queue_req(&app).await { match super::request::upload_coverart_queue_req(&app).await {
Ok(response) => { Ok(response) => {
let resp = super::util::get_resp_data::< let resp = super::util::get_resp_data::<
@@ -637,8 +756,6 @@ mod tests {
song song
); );
eprintln!("Song: {:?}", song);
match queue_coverart_flow(&app, &song_queue_id).await { match queue_coverart_flow(&app, &song_queue_id).await {
Ok(response) => Ok((response, song_queue_id)), Ok(response) => Ok((response, song_queue_id)),
Err(err) => { Err(err) => {
@@ -777,6 +894,7 @@ mod tests {
}; };
let _ = db_mgr::drop_database(&tm_pool, &db_name).await; let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
sequence_flow::delete_test_songs_from_bucket().await;
} }
#[tokio::test] #[tokio::test]
+27 -8
View File
@@ -7,13 +7,14 @@ pub async fn create(
) -> Result<uuid::Uuid, sqlx::Error> { ) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
INSERT INTO "coverart" (title, directory, filename, file_type, song_id) VALUES($1, $2, $3, $4, $5) RETURNING id; INSERT INTO "coverart" (title, directory, filename, file_type, file_key, song_id) VALUES($1, $2, $3, $4, $5, $6) RETURNING id;
"#, "#,
) )
.bind(&coverart.title) .bind(&coverart.title)
.bind(&coverart.directory) .bind(&coverart.directory)
.bind(&coverart.filename) .bind(&coverart.filename)
.bind(&coverart.file_type) .bind(&coverart.file_type)
.bind(&coverart.file_key)
.bind(song_id) .bind(song_id)
.fetch_one(pool) .fetch_one(pool)
.await .await
@@ -39,7 +40,7 @@ pub async fn get_coverart(
) -> Result<simodels::coverart::CoverArt, sqlx::Error> { ) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE id = $1; SELECT id, title, directory, filename, file_type, file_key, song_id FROM "coverart" WHERE id = $1;
"#, "#,
) )
.bind(id) .bind(id)
@@ -71,6 +72,10 @@ pub async fn get_coverart(
.try_get("file_type") .try_get("file_type")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
song_id: row song_id: row
.try_get("song_id") .try_get("song_id")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
@@ -87,7 +92,7 @@ pub async fn get_coverart_with_song_id(
) -> Result<simodels::coverart::CoverArt, sqlx::Error> { ) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE song_id = $1; SELECT id, title, directory, filename, file_type, file_key, song_id FROM "coverart" WHERE song_id = $1;
"#, "#,
) )
.bind(song_id) .bind(song_id)
@@ -119,6 +124,10 @@ pub async fn get_coverart_with_song_id(
.try_get("file_type") .try_get("file_type")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
data: Vec::new(), data: Vec::new(),
song_id: row song_id: row
.try_get("song_id") .try_get("song_id")
@@ -137,7 +146,7 @@ pub async fn delete_coverart(
r#" r#"
DELETE FROM "coverart" DELETE FROM "coverart"
WHERE id = $1 WHERE id = $1
RETURNING id, title, directory, filename, file_type, song_id RETURNING id, title, directory, filename, file_type, file_key, song_id
"#, "#,
) )
.bind(id) .bind(id)
@@ -148,7 +157,15 @@ pub async fn delete_coverart(
}); });
match result { match result {
Ok(row) => Ok(simodels::coverart::CoverArt { Ok(row) => parse_row(&row).await,
Err(_err) => Err(sqlx::Error::RowNotFound),
}
}
async fn parse_row(
row: &sqlx::postgres::PgRow,
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
Ok(simodels::coverart::CoverArt {
id: row id: row
.try_get("id") .try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
@@ -169,12 +186,14 @@ pub async fn delete_coverart(
.try_get("file_type") .try_get("file_type")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
song_id: row song_id: row
.try_get("song_id") .try_get("song_id")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
data: Vec::new(), data: Vec::new(),
}), })
Err(_err) => Err(sqlx::Error::RowNotFound),
}
} }
+2 -82
View File
@@ -1,16 +1,11 @@
use sqlx::Row; use sqlx::Row;
pub async fn insert( pub async fn insert(pool: &sqlx::PgPool, file_type: &str) -> Result<uuid::Uuid, sqlx::Error> {
pool: &sqlx::PgPool,
data: &Vec<u8>,
file_type: &str,
) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
INSERT INTO "coverartQueue" (data, file_type) VALUES($1, $2) RETURNING id; INSERT INTO "coverartQueue" (file_type) VALUES($1) RETURNING id;
"#, "#,
) )
.bind(data)
.bind(file_type) .bind(file_type)
.fetch_one(pool) .fetch_one(pool)
.await .await
@@ -120,78 +115,3 @@ pub async fn get_coverart_queue_with_song_queue_id(
Err(_) => Err(sqlx::Error::RowNotFound), Err(_) => Err(sqlx::Error::RowNotFound),
} }
} }
pub async fn get_coverart_queue_data_with_id(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<Vec<u8>, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT data FROM "coverartQueue" WHERE id = $1;
"#,
)
.bind(id)
.fetch_one(pool)
.await
.map_err(|e| {
eprintln!("Error querying data: {e:?}");
});
match result {
Ok(row) => Ok(row
.try_get("data")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap()),
Err(_) => Err(sqlx::Error::RowNotFound),
}
}
pub async fn get_coverart_queue_data_with_song_queue_id(
pool: &sqlx::PgPool,
song_queue_id: &uuid::Uuid,
) -> Result<Vec<u8>, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT data FROM "coverartQueue" WHERE song_queue_id = $1;
"#,
)
.bind(song_queue_id)
.fetch_one(pool)
.await
.map_err(|e| {
eprintln!("Error querying data: {e}");
});
match result {
Ok(row) => Ok(row
.try_get("data")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap()),
Err(_) => Err(sqlx::Error::RowNotFound),
}
}
pub async fn wipe_data(
pool: &sqlx::PgPool,
coverart_queue_id: &uuid::Uuid,
) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query(
r#"
UPDATE "coverartQueue" SET data = NULL WHERE id = $1 RETURNING id;
"#,
)
.bind(coverart_queue_id)
.fetch_one(pool)
.await
.map_err(|e| {
eprintln!("Error updating query: {e}");
});
match result {
Ok(row) => Ok(row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap()),
Err(_) => Err(sqlx::Error::RowNotFound),
}
}
+106
View File
@@ -96,3 +96,109 @@ 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),
}
}
}
}
-50
View File
@@ -251,53 +251,3 @@ pub async fn get_song_queue(
Err(_err) => Err(sqlx::Error::RowNotFound), Err(_err) => Err(sqlx::Error::RowNotFound),
} }
} }
/*
pub async fn wipe_data(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query(
r#"
UPDATE "songQueue" SET data = NULL WHERE id = $1 RETURNING id;
"#,
)
.bind(id)
.fetch_one(pool)
.await
.map_err(|e| {
eprintln!("Error updating record: {e}");
});
match result {
Ok(row) => Ok(row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap()),
Err(_) => Err(sqlx::Error::RowNotFound),
}
}
pub async fn get_data(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<Vec<u8>, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT data FROM "songQueue"
WHERE id = $1;
"#,
)
.bind(id)
.fetch_one(pool)
.await
.map_err(|e| {
eprintln!("Error inserting: {e}");
});
match result {
Ok(row) => {
let data = row
.try_get("data")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap();
Ok(data)
}
Err(_err) => Err(sqlx::Error::RowNotFound),
}
}
*/
+16 -3
View File
@@ -6,8 +6,8 @@ pub async fn insert(
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> { ) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
INSERT INTO "song" (title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, filename, directory, user_id) INSERT INTO "song" (title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, filename, directory, file_key, user_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING date_created, id; VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) RETURNING date_created, id;
"# "#
) )
.bind(&song.title) .bind(&song.title)
@@ -24,6 +24,7 @@ pub async fn insert(
.bind(&song.audio_type) .bind(&song.audio_type)
.bind(&song.filename) .bind(&song.filename)
.bind(&song.directory) .bind(&song.directory)
.bind(&song.file_key)
.bind(song.user_id) .bind(song.user_id)
.fetch_one(pool) .fetch_one(pool)
.await .await
@@ -133,6 +134,10 @@ pub async fn get_song(
.try_get("directory") .try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time), date_created: Some(date_created_time),
user_id: row user_id: row
.try_get("user_id") .try_get("user_id")
@@ -228,6 +233,10 @@ pub async fn get_all_songs(pool: &sqlx::PgPool) -> Result<Vec<simodels::song::So
.try_get("directory") .try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time), date_created: Some(date_created_time),
user_id: row user_id: row
.try_get("user_id") .try_get("user_id")
@@ -254,7 +263,7 @@ pub async fn delete_song(
r#" r#"
DELETE FROM "song" DELETE FROM "song"
WHERE id = $1 WHERE id = $1
RETURNING id, title, artist, album, album_artist, genre, year, disc, track, track_count, disc_count, duration, audio_type, date_created, filename, directory, user_id RETURNING id, title, artist, album, album_artist, genre, year, disc, track, track_count, disc_count, duration, audio_type, date_created, filename, directory, file_key, user_id
"#, "#,
) )
.bind(id) .bind(id)
@@ -332,6 +341,10 @@ pub async fn delete_song(
.try_get("directory") .try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time), date_created: Some(date_created_time),
user_id: row user_id: row
.try_get("user_id") .try_get("user_id")
+10 -1
View File
@@ -28,11 +28,18 @@ CREATE TABLE IF NOT EXISTS "metadataQueue" (
-- Table to store queued coverart -- Table to store queued coverart
CREATE TABLE IF NOT EXISTS "coverartQueue" ( CREATE TABLE IF NOT EXISTS "coverartQueue" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
data BYTEA NULL,
file_type TEXT NOT NULL, file_type TEXT NOT NULL,
song_queue_id UUID NULL song_queue_id UUID NULL
); );
CREATE TABLE IF NOT EXISTS "coverartQueueData" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
file_key TEXT NOT NULL,
bucket TEXT NOT NULL,
region TEXT NOT NULL,
coverart_queue_id UUID NOT NULL
);
-- Create an index for better query performance -- Create an index for better query performance
CREATE INDEX metadata_queue_data_metadata ON "metadataQueue" USING gin (metadata); CREATE INDEX metadata_queue_data_metadata ON "metadataQueue" USING gin (metadata);
@@ -54,6 +61,7 @@ CREATE TABLE IF NOT EXISTS "song" (
date_created timestamptz DEFAULT now(), date_created timestamptz DEFAULT now(),
filename TEXT NOT NULL, filename TEXT NOT NULL,
directory TEXT NOT NULL, directory TEXT NOT NULL,
file_key TEXT NOT NULL,
user_id UUID NULL user_id UUID NULL
); );
@@ -64,5 +72,6 @@ CREATE TABLE IF NOT EXISTS "coverart" (
directory TEXT NOT NULL, directory TEXT NOT NULL,
filename TEXT NOT NULL, filename TEXT NOT NULL,
file_type TEXT NOT NULL, file_type TEXT NOT NULL,
file_key TEXT NOT NULL,
song_id UUID NOT NULL song_id UUID NOT NULL
); );
@@ -1,6 +1,11 @@
-- Add migration script here -- Add migration script here
INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, user_id) VALUES('44cf7940-34ff-489f-9124-d0ec90a55af9', 'Hypocrite Like The Rest', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 1, 1, 9, 1, 139, 'flac', '2020-01-01 13:00:00-05', 'track01.flac', 'tests/I', '47491f9b-725a-4ba4-b9a5-711e1be46670'); INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, file_key, user_id)
INSERT INTO "coverart" (id, title, directory, filename, file_type, song_id) VALUES('996122cd-5ae9-4013-9934-60768d3006ed', 'I', 'tests/I', 'Coverart-1.jpg', 'jpeg', '44cf7940-34ff-489f-9124-d0ec90a55af9'); VALUES('44cf7940-34ff-489f-9124-d0ec90a55af9', 'Hypocrite Like The Rest', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 1, 1, 9, 1, 139, 'flac', '2020-01-01 13:00:00-05', 'track01.flac', 'tests/I', 'processed/song/track01.flac', '47491f9b-725a-4ba4-b9a5-711e1be46670');
INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, user_id) VALUES('94cf7940-34ff-489f-9124-d0ec90a55af4', 'It''s Too Late', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 2, 1, 9, 1, 116, 'flac', '2020-01-01 13:01:00-05', 'track02.flac', 'tests/I', '47491f9b-725a-4ba4-b9a5-711e1be46670'); INSERT INTO "coverart" (id, title, directory, filename, file_type, file_key, song_id)
INSERT INTO "coverart" (id, title, directory, filename, file_type, song_id) VALUES('d96122cd-5ae9-4013-9934-60768d3006e9', 'I', 'tests/I', 'Coverart-2.jpg', 'jpeg', '94cf7940-34ff-489f-9124-d0ec90a55af4'); VALUES('996122cd-5ae9-4013-9934-60768d3006ed', 'I', 'tests/I', 'Coverart-1.jpg', 'jpeg', 'processed/coverart/Coverart-1.jpg', '44cf7940-34ff-489f-9124-d0ec90a55af9');
INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, file_key, user_id)
VALUES('94cf7940-34ff-489f-9124-d0ec90a55af4', 'It''s Too Late', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 2, 1, 9, 1, 116, 'flac', '2020-01-01 13:01:00-05', 'track02.flac', 'tests/I', 'processed/song/track02.flac', '47491f9b-725a-4ba4-b9a5-711e1be46670');
INSERT INTO "coverart" (id, title, directory, filename, file_type, file_key, song_id)
VALUES('d96122cd-5ae9-4013-9934-60768d3006e9', 'I', 'tests/I', 'Coverart-2.jpg', 'jpeg', 'processed/coverart/Coverart-2.jpg', '94cf7940-34ff-489f-9124-d0ec90a55af4');