2021-06-24 21:06:58 +08:00
|
|
|
use actix_web::{web, HttpResponse};
|
2021-06-29 21:25:18 +08:00
|
|
|
use log::debug;
|
2021-09-21 19:23:22 +08:00
|
|
|
use meilisearch_lib::MeiliSearch;
|
2021-05-31 22:03:39 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-05-05 20:11:56 +08:00
|
|
|
use crate::error::ResponseError;
|
2021-06-24 21:06:58 +08:00
|
|
|
use crate::extractors::authentication::{policies::*, GuardedData};
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-07-05 20:29:20 +08:00
|
|
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
|
|
|
cfg.service(web::resource("").route(web::post().to(create_dump)))
|
|
|
|
.service(web::resource("/{dump_uid}/status").route(web::get().to(get_dump_status)));
|
2020-12-12 20:32:06 +08:00
|
|
|
}
|
|
|
|
|
2021-09-29 04:22:59 +08:00
|
|
|
pub async fn create_dump(
|
|
|
|
meilisearch: GuardedData<Private, MeiliSearch>,
|
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-09-24 18:03:16 +08:00
|
|
|
let res = meilisearch.create_dump().await?;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct DumpStatusResponse {
|
|
|
|
status: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct DumpParam {
|
2021-05-11 02:25:09 +08:00
|
|
|
dump_uid: String,
|
2020-12-12 20:32:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_dump_status(
|
2021-09-24 18:03:16 +08:00
|
|
|
meilisearch: GuardedData<Private, MeiliSearch>,
|
2021-05-11 02:25:09 +08:00
|
|
|
path: web::Path<DumpParam>,
|
2020-12-12 20:32:06 +08:00
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
2021-09-24 18:03:16 +08:00
|
|
|
let res = meilisearch.dump_info(path.dump_uid.clone()).await?;
|
2021-05-11 02:25:09 +08:00
|
|
|
|
2021-06-23 18:18:34 +08:00
|
|
|
debug!("returns: {:?}", res);
|
2021-05-11 02:25:09 +08:00
|
|
|
Ok(HttpResponse::Ok().json(res))
|
2020-12-12 20:32:06 +08:00
|
|
|
}
|