2020-01-15 17:10:33 +01:00
|
|
|
use tide::Response;
|
|
|
|
use tide::IntoResponse;
|
|
|
|
use std::future::Future;
|
2019-10-31 15:00:36 +01:00
|
|
|
use crate::data::Data;
|
|
|
|
|
|
|
|
pub mod document;
|
|
|
|
pub mod health;
|
|
|
|
pub mod index;
|
|
|
|
pub mod key;
|
|
|
|
pub mod search;
|
|
|
|
pub mod setting;
|
|
|
|
pub mod stats;
|
|
|
|
pub mod stop_words;
|
|
|
|
pub mod synonym;
|
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
async fn into_response<T: IntoResponse, U: IntoResponse>(x: impl Future<Output = Result<T, U>>) -> Response {
|
|
|
|
match x.await {
|
|
|
|
Ok(resp) => resp.into_response(),
|
|
|
|
Err(resp) => resp.into_response(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn load_routes(app: &mut tide::Server<Data>) {
|
2019-10-31 15:00:36 +01:00
|
|
|
app.at("").nest(|router| {
|
2019-12-08 15:31:42 +01:00
|
|
|
// expose the web interface static files
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/").get(|_| async move {
|
|
|
|
let response = include_str!("../../public/interface.html");
|
|
|
|
response
|
2019-12-08 15:31:42 +01:00
|
|
|
});
|
|
|
|
router.at("/bulma.min.css").get(|_| async {
|
2020-01-15 17:10:33 +01:00
|
|
|
let response = include_str!("../../public/bulma.min.css");
|
|
|
|
response
|
2019-12-08 15:31:42 +01:00
|
|
|
});
|
|
|
|
|
2019-10-31 15:00:36 +01:00
|
|
|
router.at("/indexes").nest(|router| {
|
2019-11-20 11:24:08 +01:00
|
|
|
router
|
|
|
|
.at("/")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(index::list_indexes(ctx)))
|
|
|
|
.post(|ctx| into_response(index::create_index(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/search").post(|ctx| into_response(search::search_multi_index(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
router.at("/:index").nest(|router| {
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/search").get(|ctx| into_response(search::search_with_url_query(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
router.at("/updates").nest(|router| {
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/").get(|ctx| into_response(index::get_all_updates_status(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/:update_id").get(|ctx| into_response(index::get_update_status(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
router
|
|
|
|
.at("/")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(index::get_index(ctx)))
|
|
|
|
.put(|ctx| into_response(index::update_index(ctx)))
|
|
|
|
.delete(|ctx| into_response(index::delete_index(ctx)));
|
2019-11-19 17:40:11 +01:00
|
|
|
|
2019-10-31 15:00:36 +01:00
|
|
|
router.at("/documents").nest(|router| {
|
|
|
|
router
|
|
|
|
.at("/")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(document::get_all_documents(ctx)))
|
|
|
|
.post(|ctx| into_response(document::add_or_replace_multiple_documents(ctx)))
|
|
|
|
.put(|ctx| into_response(document::add_or_update_multiple_documents(ctx)))
|
|
|
|
.delete(|ctx| into_response(document::clear_all_documents(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
router.at("/:identifier").nest(|router| {
|
|
|
|
router
|
|
|
|
.at("/")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(document::get_document(ctx)))
|
|
|
|
.delete(|ctx| into_response(document::delete_document(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
router
|
2020-01-02 12:24:29 +01:00
|
|
|
.at("/delete-batch")
|
2020-01-15 17:10:33 +01:00
|
|
|
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
|
2020-01-02 16:30:34 +01:00
|
|
|
router.at("/settings").nest(|router| {
|
2020-01-16 19:19:44 +01:00
|
|
|
|
|
|
|
router
|
|
|
|
.get(|ctx| into_response(setting::get_all(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_all(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_all(ctx)));
|
|
|
|
|
|
|
|
router.at("/ranking").nest(|router| {
|
|
|
|
|
|
|
|
router
|
|
|
|
.get(|ctx| into_response(setting::get_ranking(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_ranking(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_ranking(ctx)));
|
|
|
|
|
|
|
|
router.at("/rules")
|
|
|
|
.get(|ctx| into_response(setting::get_rules(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_rules(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_rules(ctx)));
|
|
|
|
|
|
|
|
router.at("/distinct")
|
|
|
|
.get(|ctx| into_response(setting::get_distinct(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_distinct(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_distinct(ctx)));
|
|
|
|
});
|
|
|
|
|
|
|
|
router.at("/attributes").nest(|router| {
|
|
|
|
router
|
|
|
|
.get(|ctx| into_response(setting::get_attributes(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_attributes(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_attributes(ctx)));
|
|
|
|
|
|
|
|
router.at("/identifier")
|
|
|
|
.get(|ctx| into_response(setting::get_identifier(ctx)));
|
|
|
|
|
|
|
|
router.at("/searchable")
|
|
|
|
.get(|ctx| into_response(setting::get_searchable(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_searchable(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_searchable(ctx)));
|
|
|
|
|
|
|
|
router.at("/displayed")
|
|
|
|
.get(|ctx| into_response(setting::get_displayed(ctx)))
|
|
|
|
.post(|ctx| into_response(setting::update_displayed(ctx)))
|
|
|
|
.delete(|ctx| into_response(setting::delete_displayed(ctx)));
|
|
|
|
});
|
|
|
|
|
2020-01-02 17:19:08 +01:00
|
|
|
router.at("/synonyms")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(synonym::get(ctx)))
|
|
|
|
.post(|ctx| into_response(synonym::update(ctx)))
|
|
|
|
.delete(|ctx| into_response(synonym::delete(ctx)));
|
2020-01-02 17:19:08 +01:00
|
|
|
|
|
|
|
router.at("/stop-words")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(stop_words::get(ctx)))
|
|
|
|
.post(|ctx| into_response(stop_words::update(ctx)))
|
|
|
|
.delete(|ctx| into_response(stop_words::delete(ctx)));
|
2020-01-16 19:19:44 +01:00
|
|
|
});
|
2020-01-02 17:19:08 +01:00
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/stats").get(|ctx| into_response(stats::index_stat(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.at("/keys").nest(|router| {
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/").get(|ctx| into_response(key::list(ctx))).post(|ctx| into_response(key::create(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
|
|
|
router
|
|
|
|
.at("/:key")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(key::get(ctx)))
|
|
|
|
.put(|ctx| into_response(key::update(ctx)))
|
|
|
|
.delete(|ctx| into_response(key::delete(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.at("").nest(|router| {
|
|
|
|
router
|
|
|
|
.at("/health")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(health::get_health(ctx)))
|
|
|
|
.put(|ctx| into_response(health::change_healthyness(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
router.at("/stats").get(|ctx| into_response(stats::get_stats(ctx)));
|
|
|
|
router.at("/version").get(|ctx| into_response(stats::get_version(ctx)));
|
|
|
|
router.at("/sys-info").get(|ctx| into_response(stats::get_sys_info(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
router
|
|
|
|
.at("/sys-info/pretty")
|
2020-01-15 17:10:33 +01:00
|
|
|
.get(|ctx| into_response(stats::get_sys_info_pretty(ctx)));
|
2019-10-31 15:00:36 +01:00
|
|
|
});
|
|
|
|
}
|