S3 song download #260
@@ -182,7 +182,7 @@ pub mod endpoint {
|
|||||||
|
|
||||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
let data = labyrinth::Data {
|
let data = labyrinth::Data {
|
||||||
raw_data: raw_data,
|
raw_data,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-38
@@ -137,19 +137,14 @@ 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();
|
||||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
|
|
||||||
println!("Wut?");
|
|
||||||
|
|
||||||
match repo_queue::data::get_with_song_queue_id(&pool, &payload.song_queue_id).await {
|
match repo_queue::data::get_with_song_queue_id(&pool, &payload.song_queue_id).await {
|
||||||
Ok((_id, file_key, _bucket, _region, _)) => match lr.download(&file_key).await {
|
Ok((_id, file_key, _bucket, _region, _)) => match lr.download(&file_key).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
println!("Okay!");
|
|
||||||
println!("File key: {:?}", file_key);
|
|
||||||
song.data = data;
|
song.data = data;
|
||||||
let dir = std::path::Path::new(&song.directory);
|
let dir = std::path::Path::new(&song.directory);
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
@@ -165,7 +160,6 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
song.file_key = format!("processed/song/{}", song.filename);
|
song.file_key = format!("processed/song/{}", song.filename);
|
||||||
println!("Processed file key: {:?}", song.file_key);
|
|
||||||
let data_of_song = labyrinth::Data {
|
let data_of_song = labyrinth::Data {
|
||||||
raw_data: song.data.clone(),
|
raw_data: song.data.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -182,14 +176,12 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error inserting");
|
|
||||||
response.message =
|
response.message =
|
||||||
format!("{:?} song {:?}", err.to_string(), song);
|
format!("{:?} song {:?}", err.to_string(), song);
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error uploading");
|
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
(
|
(
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
@@ -197,34 +189,6 @@ pub mod endpoint {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
match song.save_to_filesystem() {
|
|
||||||
Ok(_) =>
|
|
||||||
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) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(
|
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
axum::Json(response),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
@@ -343,7 +307,7 @@ pub mod endpoint {
|
|||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Will no longer be needed with s3
|
// TODO: At some point, directory will no longer be needed with s3
|
||||||
song.directory = sienvy::environment::get_root_directory().value;
|
song.directory = sienvy::environment::get_root_directory().value;
|
||||||
song.data = data;
|
song.data = data;
|
||||||
|
|
||||||
@@ -517,7 +481,6 @@ 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 {
|
match lr.delete(&song.file_key).await {
|
||||||
Ok(_) => match coverart.remove_from_filesystem() {
|
Ok(_) => match coverart.remove_from_filesystem() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|||||||
+4
-27
@@ -500,8 +500,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod sequence_flow {
|
mod sequence_flow {
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
pub const TEST_SONG_01_FILE_KEY: &str = "processed/song/track01.flac";
|
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_SONG_02_FILE_KEY: &str = "processed/song/track02.flac";
|
||||||
|
|
||||||
@@ -511,8 +509,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upload_test_songs_to_bucket() {
|
pub async fn upload_test_songs_to_bucket() {
|
||||||
let lab_config = soaricarus_api::util::maze::get_config();
|
|
||||||
|
|
||||||
let songs = vec![
|
let songs = vec![
|
||||||
SongBucket {
|
SongBucket {
|
||||||
file_key: TEST_SONG_01_FILE_KEY.to_string(),
|
file_key: TEST_SONG_01_FILE_KEY.to_string(),
|
||||||
@@ -524,15 +520,14 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let lab_config = soaricarus_api::util::maze::get_config();
|
||||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
|
|
||||||
for song in &songs {
|
for song in &songs {
|
||||||
let p = std::path::Path::new(&song.path);
|
let p = std::path::Path::new(&song.path);
|
||||||
// match std::fs::File::open(p) {
|
|
||||||
match tokio::fs::File::open(p).await {
|
match tokio::fs::File::open(p).await {
|
||||||
Ok(mut _file) => {
|
Ok(mut _file) => {
|
||||||
let data = labyrinth::Data {
|
let data = labyrinth::Data {
|
||||||
// raw_data: buffer,
|
|
||||||
filepath: song.path.clone(),
|
filepath: song.path.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -543,21 +538,6 @@ mod tests {
|
|||||||
assert!(false, "Error: {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) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {err:?}");
|
assert!(false, "Error: {err:?}");
|
||||||
@@ -566,9 +546,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_test_songs_to_bucket() {
|
pub async fn delete_test_songs_from_bucket() {
|
||||||
let lab_config = soaricarus_api::util::maze::get_config();
|
|
||||||
|
|
||||||
let songs = vec![
|
let songs = vec![
|
||||||
SongBucket {
|
SongBucket {
|
||||||
file_key: TEST_SONG_01_FILE_KEY.to_string(),
|
file_key: TEST_SONG_01_FILE_KEY.to_string(),
|
||||||
@@ -580,6 +558,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let lab_config = soaricarus_api::util::maze::get_config();
|
||||||
let lr = labyrinth::Labyrinth { config: lab_config };
|
let lr = labyrinth::Labyrinth { config: lab_config };
|
||||||
|
|
||||||
for song in &songs {
|
for song in &songs {
|
||||||
@@ -715,7 +694,6 @@ mod tests {
|
|||||||
soaricarus_api::callers::song::response::create_metadata::Response,
|
soaricarus_api::callers::song::response::create_metadata::Response,
|
||||||
>(response)
|
>(response)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(false, resp.data.is_empty(), "Node");
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
resp.data.is_empty(),
|
resp.data.is_empty(),
|
||||||
@@ -731,8 +709,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) => {
|
||||||
@@ -871,6 +847,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]
|
||||||
|
|||||||
Reference in New Issue
Block a user