just hardcode the damn paths

This commit is contained in:
blek 2023-10-07 23:50:48 +10:00
parent 2cbcd06c1a
commit 7e0602be23
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 15 additions and 6 deletions

View File

@ -1,18 +1,27 @@
use warp::{reply::Reply, reject::Rejection, Filter};
use serde::{Serialize, Deserialize};
use self::get_all::get_all_f;
use super::state::SharedState;
mod get_all;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct APIError {
error: String
}
pub fn api_root() -> Box<dyn Reply> {
Box::new(warp::reply::json(&String::from("{ error: \"You have called the API root of a blek! File instance. Refer to https://git.blek.codes/blek/bfile.git for documentation.\" }")))
let err = APIError {
error: "You have called the API root of a blek! File instance. Refer to https://git.blek.codes/blek/bfile.git for documentation.".into()
};
Box::new(warp::reply::json(&err))
}
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
let api = warp::path!("api");
let api = api
warp::path!("api")
.and(warp::path::end())
.map(api_root)
.or(get_all::get_all_f(state));
api
.or(get_all_f(state))
}

View File

@ -7,7 +7,7 @@ pub async fn get_all(_state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
}
pub fn get_all_f(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("get_all")
warp::path!("api" / "get_all")
.map(move || state.clone())
.and_then(get_all)
}