diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c262911 Binary files /dev/null and b/.DS_Store differ diff --git a/src/main.rs b/src/main.rs index 9a7e513..ef55735 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use rocket::{ }; use sqlx::{mysql::MySqlPoolOptions, FromRow, MySql, Pool}; -#[derive(Deserialize)] +#[derive(Deserialize, Serialize, FromRow)] #[serde(crate = "rocket::serde")] struct Song { uuid: String, @@ -39,8 +39,6 @@ struct QueuePostPayload { #[derive(Deserialize)] #[serde(crate = "rocket::serde")] struct QueueUpdatePayload { - uuid: String, - key: String, queueid: i32 } @@ -85,6 +83,15 @@ impl Song { Ok(()) } + + pub async fn get_song(id: String, pool: &Pool) -> Result { + let song = sqlx::query_as::("SELECT * FROM song_data WHERE UUID = ?") + .bind(id) + .fetch_one(pool) + .await?; + + Ok(song) + } } impl QueueSong { @@ -209,6 +216,11 @@ async fn verify_access_key(uuid: &str, api_key: &str, pool: &State>) Ok(()) } +#[get("/getsong.php?")] +async fn get_song(pool: &State>, uuid: &str) -> Result, Status> { + Song::get_song(uuid.to_string(), pool).await.map_or(Err(Status::InternalServerError), |song| Ok(Json(song))) +} + #[get("/queue.php?")] async fn get_queue(pool: &State>, uuid: &str) -> Result>, Status> { QueueSong::get_queue(uuid.to_string(), pool).await.map_or(Err(Status::InternalServerError), |queue| Ok(Json(queue))) @@ -290,7 +302,7 @@ async fn main() -> Result<(), rocket::Error> { rocket::build() - .mount("/v2", routes![get_queue, add_to_queue, set_queue_song_played, clear_queue, set_telemetry, set_song]) + .mount("/v2", routes![get_queue, add_to_queue, set_queue_song_played, clear_queue, set_telemetry, get_song, set_song]) .manage(pool) .launch() .await?;