Compare commits

...
6 Commits
Author SHA1 Message Date
phoenix aea8b14e14 Saving changes
pr CI / Test Suite (pull_request) Failing after 2m2s
2026-08-14 11:55:19 -04:00
phoenix b3055a2521 Changed it
pr CI / Test Suite (pull_request) Failing after 3m23s
2026-08-14 10:17:36 -04:00
phoenix d20bc830f3 Go
pr CI / Test Suite (pull_request) Failing after 2m30s
2026-08-14 10:12:03 -04:00
phoenix ffe293d955 Adding code for saving to bucket
pr CI / Test Suite (pull_request) Failing after 2m50s
2026-08-14 09:33:57 -04:00
phoenix c88c8fe74b bump: simodels 2026-08-14 09:33:35 -04:00
phoenix 5b292a021c Added migrations 2026-08-14 09:33:28 -04:00
8 changed files with 251 additions and 45 deletions
Generated
+2 -2
View File
@@ -2981,8 +2981,8 @@ dependencies = [
[[package]]
name = "simodels"
version = "0.11.3"
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.3-main-fe9d101bd0-111#fe9d101bd019f91fe8c99c29721ccb0e6e90c92c"
version = "0.11.4"
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.4-4-2c1998242f-111#2c1998242fb6c1e79b14f34f40b33f5e9f90a35d"
dependencies = [
"josekit",
"rand 0.10.2",
+1 -1
View File
@@ -27,7 +27,7 @@ josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] }
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" }
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.4-4-2c1998242f-111" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.4" }
@@ -63,6 +63,7 @@ CREATE TABLE IF NOT EXISTS "song" (
date_created timestamptz DEFAULT now(),
filename TEXT NOT NULL,
directory TEXT NOT NULL,
file_type TEXT NOT NULL,
user_id UUID NULL
-- TODO: Add coverart id later. This will allow multiple songs to be linked to a single cover art
);
+100 -9
View File
@@ -137,6 +137,7 @@ pub mod endpoint {
song.filename =
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
.unwrap();
// Will no longer be needed with s3
song.directory = sienvy::environment::get_root_directory().value;
let lab_config = crate::util::maze::get_config();
@@ -159,8 +160,41 @@ pub mod endpoint {
}
}
song.file_key = format!("processed/song/{}", song.filename);
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)) => {
song.id = id;
song.date_created = Some(date_created);
response.message = String::from("Successful");
response.data.push(song);
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message =
format!("{:?} song {:?}", err.to_string(), song);
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
},
Err(err) => {
eprintln!("Error: {err:?}");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
/*
match song.save_to_filesystem() {
Ok(_) => match repo::song::insert(&pool, &song).await {
Ok(_) =>
match repo::song::insert(&pool, &song).await {
Ok((date_created, id)) => {
song.id = id;
song.date_created = Some(date_created);
@@ -183,6 +217,7 @@ pub mod endpoint {
)
}
}
*/
}
Err(err) => {
eprintln!("Error: {err:?}");
@@ -290,17 +325,41 @@ pub mod endpoint {
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> impl IntoResponse {
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();
// 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 path = std::path::Path::new(&song_path);
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 {
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 {
@@ -322,8 +381,34 @@ pub mod endpoint {
.header("content-length", file_size.to_string())
.body(axum::body::Body::from_stream(stream))
.unwrap();
Ok(rep)
match song.remove_from_filesystem() {
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((
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
@@ -347,8 +432,11 @@ pub mod endpoint {
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (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 {
Ok(song) => match simodels::song::io::to_data(&song) {
Ok(song) => match lr.download(&song.file_key).await {
Ok(data) => {
let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response();
@@ -397,6 +485,8 @@ pub mod endpoint {
axum::Json<super::response::delete_song::Response>,
) {
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 {
Ok(song) => {
@@ -420,7 +510,8 @@ pub mod endpoint {
match repo::coverart::delete_coverart(&pool, &coverart.id).await
{
Ok(deleted_coverart) => {
match song.remove_from_filesystem() {
// match song.remove_from_filesystem() {
match lr.delete(&song.file_key).await {
Ok(_) => match coverart.remove_from_filesystem() {
Ok(_) => {
response.message = String::from(
@@ -438,7 +529,7 @@ pub mod endpoint {
}
},
Err(err) => {
response.message = err.to_string();
eprintln!("Error: {err:?}");
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
}
}
+96 -1
View File
@@ -500,10 +500,103 @@ mod tests {
}
mod sequence_flow {
use std::io::Read;
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 struct SongBucket {
pub file_key: String,
pub path: String,
}
pub async fn upload_test_songs_to_bucket() {
let lab_config = soaricarus_api::util::maze::get_config();
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 lr = labyrinth::Labyrinth { config: lab_config };
for song in &songs {
let p = std::path::Path::new(&song.path);
// match std::fs::File::open(p) {
match tokio::fs::File::open(p).await {
Ok(mut _file) => {
let data = labyrinth::Data {
// raw_data: buffer,
filepath: song.path.clone(),
..Default::default()
};
match lr.upload(&song.file_key, &data).await {
Ok(_) => {}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
/*
let mut buffer: Vec<u8> = Vec::new();
match file.read_to_end(&mut buffer) {
Ok(_) => {
if buffer.is_empty() {
} else {
}
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
*/
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
};
}
}
pub async fn delete_test_songs_to_bucket() {
let lab_config = soaricarus_api::util::maze::get_config();
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 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
pub async fn queue_song_flow(
app: &axum::Router,
) -> Result<(axum::response::Response, uuid::Uuid), axum::http::Error> {
upload_test_songs_to_bucket().await;
match super::request::song_queue_req(&app).await {
Ok(response) => {
let resp = super::util::get_resp_data::<
@@ -622,6 +715,7 @@ mod tests {
soaricarus_api::callers::song::response::create_metadata::Response,
>(response)
.await;
assert_eq!(false, resp.data.is_empty(), "Node");
assert_eq!(
false,
resp.data.is_empty(),
@@ -637,7 +731,7 @@ mod tests {
song
);
eprintln!("Song: {:?}", song);
// eprintln!("Song: {:?}", song);
match queue_coverart_flow(&app, &song_queue_id).await {
Ok(response) => Ok((response, song_queue_id)),
@@ -1111,6 +1205,7 @@ mod tests {
match sequence_flow::queue_song_and_coverart_flow(&app).await {
Ok((resp_one, song_queue_id)) => {
assert!(false, "Got here 2");
let resp = util::get_resp_data::<
soaricarus_api::callers::queue::coverart::response::fetch_coverart_no_data::Response,
>(resp_one)
+16 -3
View File
@@ -6,8 +6,8 @@ pub async fn insert(
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
let result = sqlx::query(
r#"
INSERT INTO "song" (title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, filename, directory, user_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING date_created, 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, $16) RETURNING date_created, id;
"#
)
.bind(&song.title)
@@ -24,6 +24,7 @@ pub async fn insert(
.bind(&song.audio_type)
.bind(&song.filename)
.bind(&song.directory)
.bind(&song.file_key)
.bind(song.user_id)
.fetch_one(pool)
.await
@@ -133,6 +134,10 @@ pub async fn get_song(
.try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time),
user_id: row
.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")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time),
user_id: row
.try_get("user_id")
@@ -254,7 +263,7 @@ pub async fn delete_song(
r#"
DELETE FROM "song"
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)
@@ -332,6 +341,10 @@ pub async fn delete_song(
.try_get("directory")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
file_key: row
.try_get("file_key")
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(),
date_created: Some(date_created_time),
user_id: row
.try_get("user_id")
+1
View File
@@ -61,6 +61,7 @@ CREATE TABLE IF NOT EXISTS "song" (
date_created timestamptz DEFAULT now(),
filename TEXT NOT NULL,
directory TEXT NOT NULL,
file_type TEXT NOT NULL,
user_id UUID NULL
);
@@ -1,6 +1,11 @@
-- 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 "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');
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('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, song_id) VALUES('d96122cd-5ae9-4013-9934-60768d3006e9', 'I', 'tests/I', 'Coverart-2.jpg', 'jpeg', '94cf7940-34ff-489f-9124-d0ec90a55af4');
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');
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, song_id)
VALUES('d96122cd-5ae9-4013-9934-60768d3006e9', 'I', 'tests/I', 'Coverart-2.jpg', 'jpeg', '94cf7940-34ff-489f-9124-d0ec90a55af4');