Song queue #258
+12
-19
@@ -213,28 +213,21 @@ pub mod endpoint {
|
|||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
println!("Result: {res:?}");
|
println!("Result: {res:?}");
|
||||||
|
|
||||||
println!("Downloading file");
|
println!("Saving to db");
|
||||||
match lr.download(&file_path).await {
|
|
||||||
Ok(res) => {
|
|
||||||
if res.is_empty() {
|
|
||||||
println!("This should not be empty");
|
|
||||||
} else {
|
|
||||||
println!("Size: {:?}", res.len());
|
|
||||||
println!("Going to delete file");
|
|
||||||
|
|
||||||
match lr.delete(&file_path).await {
|
match repo::data::insert(
|
||||||
Ok(res) => {
|
&pool,
|
||||||
println!("Result: {res:?}");
|
&file_path,
|
||||||
println!("Deleted");
|
&lr.config.bucket,
|
||||||
}
|
&lr.config.region,
|
||||||
Err(err) => {
|
&queued_song,
|
||||||
eprintln!("Error: {err:?}");
|
)
|
||||||
}
|
.await
|
||||||
}
|
{
|
||||||
}
|
Ok(_id) => {}
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
|
return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
use sqlx::Row;
|
||||||
|
|
||||||
|
pub async fn insert(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
file_key: &str,
|
||||||
|
bucket: &str,
|
||||||
|
region: &str,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
INSERT INTO "songQueueData" (file_key, bucket, region, song_queue_id) VALUES($1, $2, $3, $4) RETURNING id;
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(file_key)
|
||||||
|
.bind(bucket)
|
||||||
|
.bind(region)
|
||||||
|
.bind(song_queue_id)
|
||||||
|
.fetch_one(pool).await {
|
||||||
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
Err(_err) => Err(sqlx::Error::RowNotFound),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<(uuid::Uuid, String, String, String, uuid::Uuid), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, file_key, bucket, region, song_queue_id FROM "songQueueData"
|
||||||
|
WHERE id = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(id)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
let file_key: String = row.try_get("file_key")?;
|
||||||
|
let bucket: String = row.try_get("bucket")?;
|
||||||
|
let region: String = row.try_get("region")?;
|
||||||
|
let song_queue_id: uuid::Uuid = row.try_get("song_queue_id")?;
|
||||||
|
|
||||||
|
Ok((*id, file_key, bucket, region, song_queue_id))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_with_song_queue_id(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<(uuid::Uuid, String, String, String, uuid::Uuid), sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, file_key, bucket, region, song_queue_id FROM "songQueueData"
|
||||||
|
WHERE song_queue_id = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(song_queue_id)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
|
let file_key: String = row.try_get("file_key")?;
|
||||||
|
let bucket: String = row.try_get("bucket")?;
|
||||||
|
let region: String = row.try_get("region")?;
|
||||||
|
|
||||||
|
Ok((id, file_key, bucket, region, *song_queue_id))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod coverart;
|
pub mod coverart;
|
||||||
|
pub mod data;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod song;
|
pub mod song;
|
||||||
|
|||||||
Reference in New Issue
Block a user