synthwave/src/route/admin.rs

38 lines
1,018 B
Rust
Raw Normal View History

2024-08-12 23:52:16 +00:00
use super::api_error;
use super::FallibleApiResponse;
2024-10-04 12:38:35 +00:00
use crate::get_pg;
use crate::route::vec_to_api;
2024-08-12 23:52:16 +00:00
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);
2024-10-04 12:38:35 +00:00
let singles: Vec<Track> =
sqlx::query_as("SELECT * FROM track WHERE album IS NULL AND artist IS NOT NULL")
.fetch_all(get_pg!())
.await
.unwrap();
2024-08-16 10:33:32 +00:00
2024-09-19 14:44:44 +00:00
Ok(json!(vec_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-09-19 14:44:44 +00:00
Ok(json!(vec_to_api(&orphans).await))
2024-08-16 10:24:02 +00:00
}