This commit is contained in:
parent
44c7748a34
commit
555c874291
7 changed files with 247 additions and 224 deletions
422
Cargo.lock
generated
422
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -240,6 +240,9 @@ impl Track {
|
|||
self.transcode("aac", bitrate, "aac")
|
||||
}
|
||||
|
||||
// TODO : Transcoding Cache
|
||||
// File (Blob) based Cache with auto clean based on size (ctime)
|
||||
|
||||
/// Transcodes audio from its original format to the specified codec and extension.
|
||||
///
|
||||
/// This function creates a new directory for the transceded audio if it does not exist,
|
||||
|
|
|
@ -36,7 +36,7 @@ async fn rocket() -> _ {
|
|||
|
||||
// create initial admin user
|
||||
if User::find("admin").await.is_none() {
|
||||
User::create("admin", "admin", UserRole::Admin).await;
|
||||
User::create("admin".to_string(), "admin", UserRole::Admin).await;
|
||||
}
|
||||
|
||||
rocket::build()
|
||||
|
@ -71,7 +71,8 @@ async fn rocket() -> _ {
|
|||
route::admin::get_singles_route,
|
||||
route::event::event_report_route,
|
||||
route::search::search_route,
|
||||
route::track::track_lyrics_route
|
||||
route::track::track_lyrics_route,
|
||||
route::album::random_albums_route
|
||||
],
|
||||
)
|
||||
.manage(lib)
|
||||
|
|
|
@ -5,6 +5,7 @@ use crate::library::Libary;
|
|||
use based::request::api::{api_error, to_uuid, vec_to_api, FallibleApiResponse, ToAPI};
|
||||
use based::request::assets::DataResponse;
|
||||
use based::use_api_cache;
|
||||
use rand::seq::SliceRandom;
|
||||
use rocket::tokio::io::AsyncReadExt;
|
||||
use rocket::{get, tokio, State};
|
||||
use serde_json::json;
|
||||
|
@ -54,7 +55,19 @@ pub async fn album_cover_route(
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "image/png", Some(60 * 60 * 24 * 5)))
|
||||
Some(DataResponse::new(
|
||||
buf,
|
||||
"image/png".to_string(),
|
||||
Some(60 * 60 * 24 * 5),
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/albums/random")]
|
||||
pub async fn random_albums_route(cache: &State<RouteCache>) -> FallibleApiResponse {
|
||||
let mut albums = Album::find_all().await;
|
||||
albums.shuffle(&mut rand::thread_rng());
|
||||
let albums = vec_to_api(&albums).await;
|
||||
Ok(json!(albums))
|
||||
}
|
||||
|
||||
#[get("/albums/latest")]
|
||||
|
|
|
@ -30,7 +30,11 @@ pub async fn artist_image_route(id: &str, cache: &State<RouteCache>) -> Option<D
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "image/png", Some(60 * 60 * 24 * 5)))
|
||||
Some(DataResponse::new(
|
||||
buf,
|
||||
"image/png".to_string(),
|
||||
Some(60 * 60 * 24 * 5),
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/artist/<id>")]
|
||||
|
|
|
@ -51,7 +51,11 @@ pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<Da
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/ogg", Some(60 * 60 * 24 * 5)))
|
||||
Some(DataResponse::new(
|
||||
buf,
|
||||
"audio/ogg".to_string(),
|
||||
Some(60 * 60 * 24 * 5),
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/audio/opus128")]
|
||||
|
@ -69,7 +73,11 @@ pub async fn track_audio_opus128_route(
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/opus", Some(60 * 60 * 24 * 5)))
|
||||
Some(DataResponse::new(
|
||||
buf,
|
||||
"audio/opus".to_string(),
|
||||
Some(60 * 60 * 24 * 5),
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/audio/aac128")]
|
||||
|
@ -84,7 +92,11 @@ pub async fn track_audio_aac128_route(track_id: &str, lib: &State<Libary>) -> Op
|
|||
.await
|
||||
.ok()?;
|
||||
|
||||
Some(DataResponse::new(buf, "audio/aac", Some(60 * 60 * 24 * 5)))
|
||||
Some(DataResponse::new(
|
||||
buf,
|
||||
"audio/aac".to_string(),
|
||||
Some(60 * 60 * 24 * 5),
|
||||
))
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/lyrics")]
|
||||
|
|
|
@ -58,7 +58,7 @@ pub async fn user_create_route(user: Json<LoginData>, u: APIUser) -> FallibleApi
|
|||
let u = u.0;
|
||||
check_admin!(u);
|
||||
|
||||
let new_user = User::create(&user.username, &user.password, UserRole::Regular)
|
||||
let new_user = User::create(user.username.clone(), &user.password, UserRole::Regular)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue