Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13015e0fe3
|
||
|
|
f3f6dcba94
|
||
|
|
ed238dccab
|
Generated
+2
-2
@@ -2972,8 +2972,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "simodels"
|
||||
version = "0.11.4"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.4#d6d719741945ef7719ab1db3e0ef3c617b5bb909"
|
||||
version = "0.11.5"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.5-main-94d97cb81d-111#94d97cb81ddb46b06d34cb1eee41362728b8998e"
|
||||
dependencies = [
|
||||
"josekit",
|
||||
"rand 0.10.2",
|
||||
|
||||
+1
-1
@@ -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.2" }
|
||||
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.4" }
|
||||
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.1" }
|
||||
labyrinth = { git = "ssh://git@git.kundeng.us/phoenix/labyrinth.git", tag = "v0.0.5" }
|
||||
|
||||
|
||||
@@ -74,5 +74,6 @@ CREATE TABLE IF NOT EXISTS "coverart" (
|
||||
directory TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
file_type TEXT NOT NULL,
|
||||
file_key TEXT NOT NULL,
|
||||
song_id UUID NOT NULL
|
||||
);
|
||||
|
||||
+12
-29
@@ -127,41 +127,24 @@ pub mod endpoint {
|
||||
coverart.title = song.album.clone();
|
||||
coverart.file_type = file_type.file_type;
|
||||
coverart.data = data.raw_data;
|
||||
coverart.file_key = new_file_key;
|
||||
|
||||
match coverart.save_to_filesystem() {
|
||||
Ok(_) => {
|
||||
match repo::coverart::create(
|
||||
&pool,
|
||||
&coverart,
|
||||
&payload.song_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(id) => {
|
||||
coverart.song_id = payload.song_id;
|
||||
coverart.id = id;
|
||||
println!("Cover Art created");
|
||||
match repo::coverart::create(&pool, &coverart, &payload.song_id)
|
||||
.await
|
||||
{
|
||||
Ok(id) => {
|
||||
coverart.song_id = payload.song_id;
|
||||
coverart.id = id;
|
||||
println!("Cover Art created");
|
||||
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(coverart);
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(coverart);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
axum::http::StatusCode::BAD_REQUEST,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
}
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+50
-31
@@ -7,13 +7,14 @@ pub async fn create(
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
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.directory)
|
||||
.bind(&coverart.filename)
|
||||
.bind(&coverart.file_type)
|
||||
.bind(&coverart.file_key)
|
||||
.bind(song_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
@@ -39,7 +40,7 @@ pub async fn get_coverart(
|
||||
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
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)
|
||||
@@ -71,6 +72,10 @@ pub async fn get_coverart(
|
||||
.try_get("file_type")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
file_key: row
|
||||
.try_get("file_key")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
song_id: row
|
||||
.try_get("song_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -87,7 +92,7 @@ pub async fn get_coverart_with_song_id(
|
||||
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
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)
|
||||
@@ -119,6 +124,10 @@ pub async fn get_coverart_with_song_id(
|
||||
.try_get("file_type")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
file_key: row
|
||||
.try_get("file_key")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
data: Vec::new(),
|
||||
song_id: row
|
||||
.try_get("song_id")
|
||||
@@ -137,7 +146,7 @@ pub async fn delete_coverart(
|
||||
r#"
|
||||
DELETE FROM "coverart"
|
||||
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)
|
||||
@@ -148,33 +157,43 @@ pub async fn delete_coverart(
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
title: row
|
||||
.try_get("title")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
directory: row
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
filename: row
|
||||
.try_get("filename")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
file_type: row
|
||||
.try_get("file_type")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
song_id: row
|
||||
.try_get("song_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
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
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
title: row
|
||||
.try_get("title")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
directory: row
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
filename: row
|
||||
.try_get("filename")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
file_type: row
|
||||
.try_get("file_type")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
file_key: row
|
||||
.try_get("file_key")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
song_id: row
|
||||
.try_get("song_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
data: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,5 +72,6 @@ CREATE TABLE IF NOT EXISTS "coverart" (
|
||||
directory TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
file_type TEXT NOT NULL,
|
||||
file_key TEXT NOT NULL,
|
||||
song_id UUID NOT NULL
|
||||
);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
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 "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 "coverart" (id, title, directory, filename, file_type, file_key, song_id)
|
||||
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, 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, 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');
|
||||
|
||||
Reference in New Issue
Block a user