use rocket::*; use fs::NamedFile; use mongodb::bson::doc; use super::FallibleApiResponse; use super::api_error; use crate::library::Libary; #[get("/track/")] pub async fn track_route(track_id: &str, lib: &State) -> 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()) } #[get("/track//audio")] pub async fn track_audio_route(track_id: &str, lib: &State) -> Option { let track = lib.get_track_by_id(track_id).await?; NamedFile::open(std::path::Path::new(&track.path)) .await .ok() }