2024-07-26 12:14:08 +00:00
|
|
|
use super::api_error;
|
|
|
|
use super::FallibleApiResponse;
|
2024-07-24 09:07:24 +00:00
|
|
|
use fs::NamedFile;
|
|
|
|
use mongodb::bson::doc;
|
2024-07-26 12:14:08 +00:00
|
|
|
use rocket::*;
|
2024-07-24 09:07:24 +00:00
|
|
|
|
|
|
|
use crate::library::Libary;
|
|
|
|
|
|
|
|
#[get("/track/<track_id>")]
|
|
|
|
pub async fn track_route(track_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
2024-07-26 12:14:08 +00:00
|
|
|
Ok(lib
|
|
|
|
.get_track_by_id(track_id)
|
|
|
|
.await
|
|
|
|
.ok_or_else(|| api_error("No track with that ID found"))?
|
|
|
|
.api()
|
|
|
|
.await)
|
2024-07-24 09:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/track/<track_id>/audio")]
|
|
|
|
pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
|
|
|
let track = lib.get_track_by_id(track_id).await?;
|
|
|
|
NamedFile::open(std::path::Path::new(&track.path))
|
|
|
|
.await
|
|
|
|
.ok()
|
2024-07-26 12:14:08 +00:00
|
|
|
}
|