This commit is contained in:
JMARyA 2024-07-26 14:14:08 +02:00
parent dcf546fa9c
commit 1e67f223f7
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
10 changed files with 164 additions and 92 deletions

View file

@ -1,19 +1,19 @@
use rocket::*;
use super::api_error;
use super::FallibleApiResponse;
use fs::NamedFile;
use mongodb::bson::doc;
use super::FallibleApiResponse;
use super::api_error;
use rocket::*;
use crate::library::Libary;
#[get("/track/<track_id>")]
pub async fn track_route(track_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
Ok(serde_json::to_value(
&lib.get_track_by_id(track_id)
.await
.ok_or_else(|| api_error("No track with that ID found"))?,
)
.unwrap())
Ok(lib
.get_track_by_id(track_id)
.await
.ok_or_else(|| api_error("No track with that ID found"))?
.api()
.await)
}
#[get("/track/<track_id>/audio")]
@ -22,4 +22,4 @@ pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<Na
NamedFile::open(std::path::Path::new(&track.path))
.await
.ok()
}
}