synthwave/src/route/admin.rs

40 lines
995 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;
2024-08-16 10:33:32 +00:00
use crate::route::to_api;
2024-08-12 23:52:16 +00:00
#[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);
2024-08-16 10:57:01 +00:00
let singles = Track::find(
doc! { "album_id": None::<String>, "artist_id": {"$ne": None::<String> }},
None,
)
.await
.unwrap();
2024-08-16 10:33:32 +00:00
Ok(json!(to_api(&singles).await))
2024-08-16 10:24:02 +00:00
}
#[get("/library/orphans")]
pub async fn get_orphans_route(u: User) -> FallibleApiResponse {
check_admin!(u);
let orphans = Track::get_orphans().await;
2024-08-16 10:33:32 +00:00
Ok(json!(to_api(&orphans).await))
2024-08-16 10:24:02 +00:00
}