update
This commit is contained in:
parent
a5d3c14f0c
commit
11a862f6c7
6 changed files with 158 additions and 1 deletions
16
src/route/admin.rs
Normal file
16
src/route/admin.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use super::api_error;
|
||||
use super::FallibleApiResponse;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::{get, State};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::check_admin;
|
||||
use crate::library::user::User;
|
||||
use crate::library::Libary;
|
||||
|
||||
#[get("/library/clean")]
|
||||
pub async fn clean_library(lib: &State<Libary>, u: User) -> FallibleApiResponse {
|
||||
check_admin!(u);
|
||||
lib.clean_lost_files().await;
|
||||
Ok(json!({"ok": 1}))
|
||||
}
|
|
@ -5,6 +5,7 @@ use rocket::{
|
|||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub mod admin;
|
||||
pub mod album;
|
||||
pub mod artist;
|
||||
pub mod playlist;
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
use super::api_error;
|
||||
use super::FallibleApiResponse;
|
||||
use super::ToAPI;
|
||||
use crate::library::user::User;
|
||||
use fs::NamedFile;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::{fs, get, State};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::check_admin;
|
||||
use crate::library::Libary;
|
||||
|
||||
#[get("/track/<track_id>")]
|
||||
|
@ -17,6 +20,19 @@ pub async fn track_route(track_id: &str, lib: &State<Libary>) -> FallibleApiResp
|
|||
.await)
|
||||
}
|
||||
|
||||
#[get("/track/<track_id>/reload")]
|
||||
pub async fn track_reload_meta_route(
|
||||
track_id: &str,
|
||||
lib: &State<Libary>,
|
||||
u: User,
|
||||
) -> FallibleApiResponse {
|
||||
check_admin!(u);
|
||||
lib.reload_metadata(track_id)
|
||||
.await
|
||||
.map_err(|_| api_error("Error reloading metadata"))?;
|
||||
Ok(json!({"ok": 1}))
|
||||
}
|
||||
|
||||
#[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?;
|
||||
|
|
|
@ -16,6 +16,7 @@ use serde_json::json;
|
|||
use super::api_error;
|
||||
use super::FallibleApiResponse;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! check_admin {
|
||||
($u:ident) => {
|
||||
if !$u.is_admin() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue