mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
index UID format; fix #497
This commit is contained in:
parent
041eed2a06
commit
c5b6e641a4
4 changed files with 67 additions and 2 deletions
|
@ -22,6 +22,7 @@ pub enum ResponseError {
|
|||
BadParameter(String, String),
|
||||
OpenIndex(String),
|
||||
CreateIndex(String),
|
||||
InvalidIndexUid,
|
||||
Maintenance,
|
||||
}
|
||||
|
||||
|
@ -108,6 +109,10 @@ impl IntoResponse for ResponseError {
|
|||
format!("Impossible to open index; {}", err),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
ResponseError::InvalidIndexUid => error(
|
||||
"Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).".to_string(),
|
||||
StatusCode::BAD_REQUEST,
|
||||
),
|
||||
ResponseError::Maintenance => error(
|
||||
String::from("Server is in maintenance, please try again later"),
|
||||
StatusCode::SERVICE_UNAVAILABLE,
|
||||
|
|
|
@ -138,7 +138,13 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
|
|||
let db = &ctx.state().db;
|
||||
|
||||
let uid = match body.uid {
|
||||
Some(uid) => uid,
|
||||
Some(uid) => {
|
||||
if uid.chars().all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_') {
|
||||
uid
|
||||
} else {
|
||||
return Err(ResponseError::InvalidIndexUid)
|
||||
}
|
||||
},
|
||||
None => loop {
|
||||
let uid = generate_uid();
|
||||
if db.open_index(&uid).is_none() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue