This commit is contained in:
+38
-1
@@ -137,6 +137,7 @@ pub mod endpoint {
|
|||||||
song.filename =
|
song.filename =
|
||||||
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
|
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
// Will no longer be needed with s3
|
||||||
song.directory = sienvy::environment::get_root_directory().value;
|
song.directory = sienvy::environment::get_root_directory().value;
|
||||||
|
|
||||||
let lab_config = crate::util::maze::get_config();
|
let lab_config = crate::util::maze::get_config();
|
||||||
@@ -159,8 +160,43 @@ 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() {
|
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)) => {
|
Ok((date_created, id)) => {
|
||||||
song.id = id;
|
song.id = id;
|
||||||
song.date_created = Some(date_created);
|
song.date_created = Some(date_created);
|
||||||
@@ -183,6 +219,7 @@ pub mod endpoint {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
|
|||||||
+16
-3
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user