use rocket::{ get, response::{status::BadRequest, Redirect}, uri, }; use serde_json::json; pub mod album; pub mod artist; pub mod playlist; pub mod track; pub mod user; // todo : rework api type ApiError = BadRequest; type FallibleApiResponse = Result; pub fn api_error(msg: &str) -> ApiError { BadRequest(json!({ "error": msg })) } pub trait ToAPI: Sized { /// Generate public API JSON fn api(&self) -> impl std::future::Future; } pub async fn to_api(albums: &[impl ToAPI]) -> Vec { let mut ret = Vec::new(); for e in albums { ret.push(e.api().await); } ret } #[get("/")] pub fn index_redir() -> Redirect { Redirect::to(uri!("/web")) } #[get("/manifest.json")] pub fn manifest_redir() -> Redirect { Redirect::to(uri!("/web/manifest.json")) }