2024-08-01 14:42:58 +00:00
|
|
|
use rocket::{
|
|
|
|
get,
|
|
|
|
response::{status::BadRequest, Redirect},
|
|
|
|
uri,
|
|
|
|
};
|
2024-07-24 09:07:24 +00:00
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
pub mod album;
|
2024-07-26 12:14:08 +00:00
|
|
|
pub mod artist;
|
2024-07-24 09:07:24 +00:00
|
|
|
pub mod track;
|
|
|
|
pub mod user;
|
2024-08-11 02:07:02 +00:00
|
|
|
pub mod playlist;
|
2024-07-24 09:07:24 +00:00
|
|
|
|
2024-08-01 14:36:54 +00:00
|
|
|
// todo : rework api
|
|
|
|
|
2024-07-24 09:07:24 +00:00
|
|
|
type ApiError = BadRequest<serde_json::Value>;
|
|
|
|
type FallibleApiResponse = Result<serde_json::Value, ApiError>;
|
|
|
|
|
|
|
|
pub fn api_error(msg: &str) -> ApiError {
|
|
|
|
BadRequest(json!({
|
|
|
|
"error": msg
|
|
|
|
}))
|
|
|
|
}
|
2024-08-01 14:36:54 +00:00
|
|
|
|
|
|
|
pub trait ToAPI: Sized {
|
|
|
|
/// Generate public API JSON
|
|
|
|
fn api(&self) -> impl std::future::Future<Output = serde_json::Value>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn to_api(albums: &[impl ToAPI]) -> Vec<serde_json::Value> {
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
|
|
|
|
for e in albums {
|
|
|
|
ret.push(e.api().await);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret
|
|
|
|
}
|
2024-08-01 14:42:58 +00:00
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
pub async fn index_redir() -> Redirect {
|
|
|
|
Redirect::to(uri!("/web"))
|
|
|
|
}
|
2024-08-07 19:56:09 +00:00
|
|
|
|
|
|
|
#[get("/manifest.json")]
|
|
|
|
pub async fn manifest_redir() -> Redirect {
|
|
|
|
Redirect::to(uri!("/web/manifest.json"))
|
|
|
|
}
|