finish postgres
This commit is contained in:
parent
7b7e1a4014
commit
08e24f63f4
16 changed files with 454 additions and 306 deletions
|
@ -1,9 +1,12 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use super::api_error;
|
||||
use super::no_uuid_error;
|
||||
use super::to_uuid;
|
||||
use super::FallibleApiResponse;
|
||||
use super::ToAPI;
|
||||
use crate::library::user::User;
|
||||
use fs::NamedFile;
|
||||
use mongod::ToAPI;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::{fs, get, State};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -13,7 +16,7 @@ use crate::library::Libary;
|
|||
#[get("/track/<track_id>")]
|
||||
pub async fn track_route(track_id: &str, lib: &State<Libary>) -> FallibleApiResponse {
|
||||
Ok(lib
|
||||
.get_track_by_id(track_id)
|
||||
.get_track_by_id(&to_uuid(track_id)?)
|
||||
.await
|
||||
.ok_or_else(|| api_error("No track with that ID found"))?
|
||||
.api()
|
||||
|
@ -27,7 +30,7 @@ pub async fn track_reload_meta_route(
|
|||
u: User,
|
||||
) -> FallibleApiResponse {
|
||||
check_admin!(u);
|
||||
lib.reload_metadata(track_id)
|
||||
lib.reload_metadata(&to_uuid(track_id)?)
|
||||
.await
|
||||
.map_err(|_| api_error("Error reloading metadata"))?;
|
||||
Ok(json!({"ok": 1}))
|
||||
|
@ -35,7 +38,9 @@ pub async fn track_reload_meta_route(
|
|||
|
||||
#[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?;
|
||||
let track = lib
|
||||
.get_track_by_id(&uuid::Uuid::from_str(track_id).ok()?)
|
||||
.await?;
|
||||
NamedFile::open(std::path::Path::new(&track.path))
|
||||
.await
|
||||
.ok()
|
||||
|
@ -43,12 +48,16 @@ pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<Na
|
|||
|
||||
#[get("/track/<track_id>/audio/opus128")]
|
||||
pub async fn track_audio_opus128_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
||||
let track = lib.get_track_by_id(track_id).await?;
|
||||
let track = lib
|
||||
.get_track_by_id(&uuid::Uuid::from_str(track_id).ok()?)
|
||||
.await?;
|
||||
NamedFile::open(track.get_opus(128)?).await.ok()
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/audio/aac128")]
|
||||
pub async fn track_audio_aac128_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
||||
let track = lib.get_track_by_id(track_id).await?;
|
||||
let track = lib
|
||||
.get_track_by_id(&uuid::Uuid::from_str(track_id).ok()?)
|
||||
.await?;
|
||||
NamedFile::open(track.get_aac(128)?).await.ok()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue