update
This commit is contained in:
parent
1dfb3d4964
commit
7eb2b7d00d
7 changed files with 248 additions and 63 deletions
|
@ -1,11 +1,18 @@
|
|||
use crate::library::{track, Libary};
|
||||
use crate::library::Libary;
|
||||
use based::{
|
||||
auth::User,
|
||||
check_admin,
|
||||
request::api::{api_error, to_uuid, FallibleApiResponse, ToAPI},
|
||||
request::{
|
||||
api::{api_error, to_uuid, FallibleApiResponse, ToAPI},
|
||||
assets::DataResponse,
|
||||
},
|
||||
};
|
||||
|
||||
use rocket::{
|
||||
get,
|
||||
tokio::{self, io::AsyncReadExt},
|
||||
State,
|
||||
};
|
||||
use fs::NamedFile;
|
||||
use rocket::{fs, get, State};
|
||||
use serde_json::json;
|
||||
|
||||
#[get("/track/<track_id>")]
|
||||
|
@ -32,23 +39,51 @@ 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> {
|
||||
pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<DataResponse> {
|
||||
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
|
||||
NamedFile::open(std::path::Path::new(&track.path))
|
||||
|
||||
let mut buf = Vec::new();
|
||||
tokio::fs::File::open(track.path)
|
||||
.await
|
||||
.ok()
|
||||
.ok()?
|
||||
.read(&mut buf)
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/ogg", Some(60 * 60 * 24 * 5)))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/audio/opus128")]
|
||||
pub async fn track_audio_opus128_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
||||
pub async fn track_audio_opus128_route(
|
||||
track_id: &str,
|
||||
lib: &State<Libary>,
|
||||
) -> Option<DataResponse> {
|
||||
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
|
||||
NamedFile::open(track.get_opus(128)?).await.ok()
|
||||
|
||||
let mut buf = Vec::new();
|
||||
tokio::fs::File::open(track.get_opus(128)?)
|
||||
.await
|
||||
.ok()?
|
||||
.read(&mut buf)
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/opus", Some(60 * 60 * 24 * 5)))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/audio/aac128")]
|
||||
pub async fn track_audio_aac128_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
||||
pub async fn track_audio_aac128_route(track_id: &str, lib: &State<Libary>) -> Option<DataResponse> {
|
||||
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
|
||||
NamedFile::open(track.get_aac(128)?).await.ok()
|
||||
|
||||
let mut buf = Vec::new();
|
||||
tokio::fs::File::open(track.get_aac(128)?)
|
||||
.await
|
||||
.ok()?
|
||||
.read(&mut buf)
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/aac", Some(60 * 60 * 24 * 5)))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/lyrics")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue