2021-10-14 11:32:55 +02:00
|
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
2021-06-29 15:25:18 +02:00
|
|
|
use log::debug;
|
2021-12-02 16:03:26 +01:00
|
|
|
use meilisearch_error::ResponseError;
|
2021-09-21 13:23:22 +02:00
|
|
|
use meilisearch_lib::MeiliSearch;
|
2021-05-31 16:03:39 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-10-14 11:32:55 +02:00
|
|
|
use serde_json::json;
|
2020-12-12 13:32:06 +01:00
|
|
|
|
2021-10-14 11:32:55 +02:00
|
|
|
use crate::analytics::Analytics;
|
2021-06-24 15:06:58 +02:00
|
|
|
use crate::extractors::authentication::{policies::*, GuardedData};
|
2022-03-04 20:12:44 +01:00
|
|
|
use crate::extractors::sequential_extractor::SeqHandler;
|
2020-12-12 13:32:06 +01:00
|
|
|
|
2021-07-05 14:29:20 +02:00
|
|
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
2022-03-04 20:12:44 +01:00
|
|
|
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))))
|
|
|
|
.service(
|
|
|
|
web::resource("/{dump_uid}/status").route(web::get().to(SeqHandler(get_dump_status))),
|
|
|
|
);
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
2021-09-28 22:22:59 +02:00
|
|
|
pub async fn create_dump(
|
2021-11-08 18:31:27 +01:00
|
|
|
meilisearch: GuardedData<ActionPolicy<{ actions::DUMPS_CREATE }>, MeiliSearch>,
|
2021-10-14 11:32:55 +02:00
|
|
|
req: HttpRequest,
|
2021-10-29 16:10:58 +02:00
|
|
|
analytics: web::Data<dyn Analytics>,
|
2021-09-28 22:22:59 +02:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-10-14 11:32:55 +02:00
|
|
|
analytics.publish("Dump Created".to_string(), json!({}), Some(&req));
|
|
|
|
|
2021-09-24 12:03:16 +02:00
|
|
|
let res = meilisearch.create_dump().await?;
|
2021-05-05 14:11:56 +02:00
|
|
|
|
2021-06-23 12:18:34 +02:00
|
|
|
debug!("returns: {:?}", res);
|
2021-05-11 17:34:34 +02:00
|
|
|
Ok(HttpResponse::Accepted().json(res))
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct DumpStatusResponse {
|
|
|
|
status: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct DumpParam {
|
2021-05-10 20:25:09 +02:00
|
|
|
dump_uid: String,
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_dump_status(
|
2021-11-08 18:31:27 +01:00
|
|
|
meilisearch: GuardedData<ActionPolicy<{ actions::DUMPS_GET }>, MeiliSearch>,
|
2021-05-10 20:25:09 +02:00
|
|
|
path: web::Path<DumpParam>,
|
2020-12-12 13:32:06 +01:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-09-24 12:03:16 +02:00
|
|
|
let res = meilisearch.dump_info(path.dump_uid.clone()).await?;
|
2021-05-10 20:25:09 +02:00
|
|
|
|
2021-06-23 12:18:34 +02:00
|
|
|
debug!("returns: {:?}", res);
|
2021-05-10 20:25:09 +02:00
|
|
|
Ok(HttpResponse::Ok().json(res))
|
2020-12-12 13:32:06 +01:00
|
|
|
}
|