synthwave/src/route/admin.rs

35 lines
884 B
Rust
Raw Normal View History

2024-08-12 23:52:16 +00:00
use super::api_error;
use super::FallibleApiResponse;
2024-08-16 10:24:02 +00:00
use mongod::Model;
2024-08-12 23:52:16 +00:00
use mongodb::bson::doc;
use rocket::{get, State};
use serde_json::json;
use crate::check_admin;
2024-08-16 10:24:02 +00:00
use crate::library::track::Track;
2024-08-12 23:52:16 +00:00
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}))
}
2024-08-16 10:24:02 +00:00
#[get("/library/singles")]
pub async fn get_singles_route(u: User) -> FallibleApiResponse {
check_admin!(u);
let singles = Track::find(doc! { "album_id": None::<String>}, None)
.await
.unwrap();
Ok(json!(singles))
}
#[get("/library/orphans")]
pub async fn get_orphans_route(u: User) -> FallibleApiResponse {
check_admin!(u);
let orphans = Track::get_orphans().await;
Ok(json!(orphans))
}