2021-10-14 17:32:55 +08:00
|
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
2021-06-29 21:25:18 +08:00
|
|
|
use log::debug;
|
2021-09-21 19:23:22 +08:00
|
|
|
use meilisearch_lib::MeiliSearch;
|
2022-06-06 18:38:46 +08:00
|
|
|
use meilisearch_types::error::ResponseError;
|
2021-10-14 17:32:55 +08:00
|
|
|
use serde_json::json;
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-10-14 17:32:55 +08:00
|
|
|
use crate::analytics::Analytics;
|
2021-06-24 21:06:58 +08:00
|
|
|
use crate::extractors::authentication::{policies::*, GuardedData};
|
2022-03-05 03:12:44 +08:00
|
|
|
use crate::extractors::sequential_extractor::SeqHandler;
|
2022-05-17 23:40:59 +08:00
|
|
|
use crate::task::SummarizedTaskView;
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-07-05 20:29:20 +08:00
|
|
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
2022-05-20 02:19:34 +08:00
|
|
|
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))));
|
2020-12-12 20:32:06 +08:00
|
|
|
}
|
|
|
|
|
2021-09-29 04:22:59 +08:00
|
|
|
pub async fn create_dump(
|
2021-11-09 01:31:27 +08:00
|
|
|
meilisearch: GuardedData<ActionPolicy<{ actions::DUMPS_CREATE }>, MeiliSearch>,
|
2021-10-14 17:32:55 +08:00
|
|
|
req: HttpRequest,
|
2021-10-29 22:10:58 +08:00
|
|
|
analytics: web::Data<dyn Analytics>,
|
2021-09-29 04:22:59 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-10-14 17:32:55 +08:00
|
|
|
analytics.publish("Dump Created".to_string(), json!({}), Some(&req));
|
|
|
|
|
2022-05-17 23:40:59 +08:00
|
|
|
let res: SummarizedTaskView = meilisearch.register_dump_task().await?.into();
|
2021-05-05 20:11:56 +08:00
|
|
|
|
2021-06-23 18:18:34 +08:00
|
|
|
debug!("returns: {:?}", res);
|
2021-05-11 23:34:34 +08:00
|
|
|
Ok(HttpResponse::Accepted().json(res))
|
2020-12-12 20:32:06 +08:00
|
|
|
}
|