use super::api_error; use super::FallibleApiResponse; use mongod::Model; use mongodb::bson::doc; use rocket::{get, State}; use serde_json::json; use crate::check_admin; use crate::library::track::Track; use crate::library::user::User; use crate::library::Libary; use crate::route::to_api; #[get("/library/clean")] pub async fn clean_library(lib: &State, u: User) -> FallibleApiResponse { check_admin!(u); lib.clean_lost_files().await; Ok(json!({"ok": 1})) } #[get("/library/singles")] pub async fn get_singles_route(u: User) -> FallibleApiResponse { check_admin!(u); let singles = Track::find( doc! { "album_id": None::, "artist_id": {"$ne": None:: }}, None, ) .await .unwrap(); Ok(json!(to_api(&singles).await)) } #[get("/library/orphans")] pub async fn get_orphans_route(u: User) -> FallibleApiResponse { check_admin!(u); let orphans = Track::get_orphans().await; Ok(json!(to_api(&orphans).await)) }