icarus_models version bump (#210)
* icarus_models version bump * icarus_models related changes * Code formatting * Test changeS: * Test changes * Migration changes * Migration changes * Warning fix * Cleanup * Updated readme * Removed line from migrations * Code cleanup * Version bump * cargo update * icarus_models version bump
This commit was merged in pull request #210.
This commit is contained in:
+29
-17
@@ -325,11 +325,12 @@ pub mod cov_db {
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
INSERT INTO "coverart" (title, path, song_id) VALUES($1, $2, $3) RETURNING id;
|
||||
INSERT INTO "coverart" (title, directory, filename, song_id) VALUES($1, $2, $3, $4) RETURNING id;
|
||||
"#,
|
||||
)
|
||||
.bind(&coverart.title)
|
||||
.bind(&coverart.path)
|
||||
.bind(&coverart.directory)
|
||||
.bind(&coverart.filename)
|
||||
.bind(song_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
@@ -355,7 +356,7 @@ pub mod cov_db {
|
||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, title, path, song_id FROM "coverart" WHERE id = $1;
|
||||
SELECT id, title, directory, filename, song_id FROM "coverart" WHERE id = $1;
|
||||
"#,
|
||||
)
|
||||
.bind(id)
|
||||
@@ -375,15 +376,19 @@ pub mod cov_db {
|
||||
.try_get("title")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
path: row
|
||||
.try_get("path")
|
||||
directory: row
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
filename: row
|
||||
.try_get("filename")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
data: Vec::new(),
|
||||
song_id: row
|
||||
.try_get("song_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
..Default::default()
|
||||
}),
|
||||
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||
}
|
||||
@@ -395,7 +400,7 @@ pub mod cov_db {
|
||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, title, path, song_id FROM "coverart" WHERE song_id = $1;
|
||||
SELECT id, title, directory, filename, song_id FROM "coverart" WHERE song_id = $1;
|
||||
"#,
|
||||
)
|
||||
.bind(song_id)
|
||||
@@ -415,8 +420,12 @@ pub mod cov_db {
|
||||
.try_get("title")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
path: row
|
||||
.try_get("path")
|
||||
directory: row
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
filename: row
|
||||
.try_get("filename")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
data: Vec::new(),
|
||||
@@ -437,7 +446,7 @@ pub mod cov_db {
|
||||
r#"
|
||||
DELETE FROM "coverart"
|
||||
WHERE id = $1
|
||||
RETURNING id, title, path, song_id
|
||||
RETURNING id, title, directory, filename, song_id
|
||||
"#,
|
||||
)
|
||||
.bind(id)
|
||||
@@ -457,8 +466,12 @@ pub mod cov_db {
|
||||
.try_get("title")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
path: row
|
||||
.try_get("path")
|
||||
directory: row
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
filename: row
|
||||
.try_get("filename")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
song_id: row
|
||||
@@ -701,14 +714,13 @@ pub mod endpoint {
|
||||
match crate::callers::song::song_db::get_song(&pool, &song_id).await {
|
||||
Ok(song) => {
|
||||
let directory = icarus_envy::environment::get_root_directory().await.value;
|
||||
let dir = std::path::Path::new(&directory);
|
||||
|
||||
// TODO: Make this random and the file extension should not be hard coded
|
||||
let filename = format!("{}-coverart.jpeg", &song.filename[..8]);
|
||||
let save_path = dir.join(&filename);
|
||||
let path = String::from(save_path.to_str().unwrap());
|
||||
|
||||
let mut coverart =
|
||||
icarus_models::coverart::init::init_coverart_only_path(path);
|
||||
icarus_models::coverart::init::init_coverart_dir_and_filename(
|
||||
&directory, &filename,
|
||||
);
|
||||
coverart.title = song.album.clone();
|
||||
coverart.data = data;
|
||||
|
||||
|
||||
+46
-47
@@ -81,11 +81,7 @@ pub mod request {
|
||||
duration: self.duration,
|
||||
audio_type: self.audio_type.clone(),
|
||||
user_id: self.user_id,
|
||||
// TODO: Change the type of this in icarus_models lib
|
||||
date_created: String::new(),
|
||||
filename: String::new(),
|
||||
data: Vec::new(),
|
||||
directory: String::new(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +220,7 @@ pub mod song_db {
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
song: &icarus_models::song::Song,
|
||||
) -> Result<(String, uuid::Uuid), sqlx::Error> {
|
||||
) -> 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)
|
||||
@@ -262,7 +258,7 @@ pub mod song_db {
|
||||
.try_get("date_created")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap();
|
||||
let date_created = date_created_time.to_string();
|
||||
let date_created = date_created_time;
|
||||
|
||||
Ok((date_created, id))
|
||||
}
|
||||
@@ -354,7 +350,7 @@ pub mod song_db {
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
date_created: date_created_time.to_string(),
|
||||
date_created: Some(date_created_time),
|
||||
user_id: row
|
||||
.try_get("user_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -451,7 +447,7 @@ pub mod song_db {
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
date_created: date_created_time.to_string(),
|
||||
date_created: Some(date_created_time),
|
||||
user_id: row
|
||||
.try_get("user_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -555,7 +551,7 @@ pub mod song_db {
|
||||
.try_get("directory")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap(),
|
||||
date_created: date_created_time.to_string(),
|
||||
date_created: Some(date_created_time),
|
||||
user_id: row
|
||||
.try_get("user_id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -1221,7 +1217,7 @@ pub mod endpoint {
|
||||
Ok(_) => match super::song_db::insert(&pool, &song).await {
|
||||
Ok((date_created, id)) => {
|
||||
song.id = id;
|
||||
song.date_created = date_created;
|
||||
song.date_created = Some(date_created);
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(song);
|
||||
|
||||
@@ -1495,49 +1491,52 @@ pub mod endpoint {
|
||||
.await
|
||||
{
|
||||
Ok(coverart) => {
|
||||
let coverart_path = std::path::Path::new(&coverart.path);
|
||||
if coverart_path.exists() {
|
||||
match song.song_path() {
|
||||
Ok(song_path) => {
|
||||
match super::song_db::delete_song(&pool, &song.id).await {
|
||||
Ok(deleted_song) => {
|
||||
match super::super::coverart::cov_db::delete_coverart(
|
||||
&pool,
|
||||
&coverart.id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(deleted_coverart) => {
|
||||
match std::fs::remove_file(song_path) {
|
||||
Ok(_) => match std::fs::remove_file(
|
||||
&coverart.path,
|
||||
) {
|
||||
Ok(_) => {
|
||||
response.message = String::from(super::super::response::SUCCESSFUL);
|
||||
response.data.push(super::response::delete_song::SongAndCoverArt{ song: deleted_song, coverart: deleted_coverart });
|
||||
(
|
||||
axum::http::StatusCode::OK,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
||||
}
|
||||
}
|
||||
}
|
||||
let coverart_path_str = match coverart.get_path() {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let coverart_path = std::path::Path::new(&coverart_path_str);
|
||||
|
||||
if coverart_path.exists() {
|
||||
match super::song_db::delete_song(&pool, &song.id).await {
|
||||
Ok(deleted_song) => {
|
||||
match super::super::coverart::cov_db::delete_coverart(
|
||||
&pool,
|
||||
&coverart.id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(deleted_coverart) => {
|
||||
match song.remove_from_filesystem() {
|
||||
Ok(_) => match coverart.remove_from_filesystem() {
|
||||
Ok(_) => {
|
||||
response.message = String::from(
|
||||
super::super::response::SUCCESSFUL,
|
||||
);
|
||||
response.data.push(super::response::delete_song::SongAndCoverArt{ song: deleted_song, coverart: deleted_coverart });
|
||||
(
|
||||
axum::http::StatusCode::OK,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(
|
||||
|
||||
+27
-42
@@ -1770,8 +1770,6 @@ mod tests {
|
||||
song
|
||||
);
|
||||
|
||||
eprintln!("Song: {:?}", song);
|
||||
|
||||
match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await {
|
||||
Ok(response) => {
|
||||
let resp = get_resp_data::<
|
||||
@@ -2171,14 +2169,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn other_song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error>
|
||||
{
|
||||
pub async fn other_song_id()
|
||||
-> Result<(uuid::Uuid, (String, String), (String, String)), uuid::Error> {
|
||||
match uuid::Uuid::parse_str("94cf7940-34ff-489f-9124-d0ec90a55af4") {
|
||||
Ok(id) => Ok((
|
||||
id,
|
||||
String::from("tests/I/"),
|
||||
String::from("track02.flac"),
|
||||
String::from("tests/I/Coverart-2.jpg"),
|
||||
(String::from("tests/I/"), String::from("track02.flac")),
|
||||
(String::from("tests/I/"), String::from("Coverart-2.jpg")),
|
||||
)),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
@@ -2371,7 +2368,8 @@ mod tests {
|
||||
async fn get_test_data(
|
||||
song_directory: &String,
|
||||
song_filename: &String,
|
||||
coverart_path: &String,
|
||||
coverart_directory: &String,
|
||||
coverart_filename: &String,
|
||||
) -> Result<(Vec<u8>, Vec<u8>), std::io::Error> {
|
||||
let song = icarus_models::song::Song {
|
||||
directory: song_directory.clone(),
|
||||
@@ -2380,7 +2378,8 @@ mod tests {
|
||||
};
|
||||
|
||||
let coverart = icarus_models::coverart::CoverArt {
|
||||
path: coverart_path.clone(),
|
||||
directory: coverart_directory.clone(),
|
||||
filename: coverart_filename.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -2397,45 +2396,26 @@ mod tests {
|
||||
song_directory: &String,
|
||||
song_filename: &String,
|
||||
song_data: Vec<u8>,
|
||||
coverart_path: &String,
|
||||
coverart_directory: &String,
|
||||
coverart_filename: &String,
|
||||
coverart_data: Vec<u8>,
|
||||
) -> Result<(), std::io::Error> {
|
||||
let song = icarus_models::song::Song {
|
||||
directory: song_directory.clone(),
|
||||
filename: song_filename.clone(),
|
||||
data: song_data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let coverart = icarus_models::coverart::CoverArt {
|
||||
path: coverart_path.clone(),
|
||||
directory: coverart_directory.clone(),
|
||||
filename: coverart_filename.clone(),
|
||||
data: coverart_data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
match song.song_path() {
|
||||
Ok(song_path) => {
|
||||
let song_p = std::path::Path::new(&song_path);
|
||||
match std::fs::File::create(song_p) {
|
||||
Ok(mut song_file) => match song_file.write_all(&song_data) {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
return Err(err);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
let coverart_p = std::path::Path::new(&coverart.path);
|
||||
match std::fs::File::create(coverart_p) {
|
||||
Ok(mut coverart_file) => match coverart_file.write_all(&coverart_data) {
|
||||
match song.save_to_filesystem() {
|
||||
Ok(_) => match coverart.save_to_filesystem() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
@@ -2462,12 +2442,16 @@ mod tests {
|
||||
|
||||
let app = super::init::app(pool).await;
|
||||
|
||||
let (id, song_directory, song_filename, coverart_path) =
|
||||
let (id, (song_directory, song_filename), (cover_directory, cover_filename)) =
|
||||
test_data::other_song_id().await.unwrap();
|
||||
let (song_data, coverart_data) =
|
||||
get_test_data(&song_directory, &song_filename, &coverart_path)
|
||||
.await
|
||||
.unwrap();
|
||||
let (song_data, coverart_data) = get_test_data(
|
||||
&song_directory,
|
||||
&song_filename,
|
||||
&cover_directory,
|
||||
&cover_filename,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let uri =
|
||||
super::format_url_with_value(crate::callers::endpoints::DELETESONG, &id).await;
|
||||
@@ -2505,7 +2489,8 @@ mod tests {
|
||||
&song_directory,
|
||||
&song_filename,
|
||||
song_data,
|
||||
&coverart_path,
|
||||
&cover_directory,
|
||||
&cover_filename,
|
||||
coverart_data,
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user