mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00:00
Clean code
This commit is contained in:
@ -213,6 +213,3 @@ merge_with_error_impl_take_error_message!(InvalidSearchSemanticRatio);
|
|||||||
merge_with_error_impl_take_error_message!(InvalidSearchRankingScoreThreshold);
|
merge_with_error_impl_take_error_message!(InvalidSearchRankingScoreThreshold);
|
||||||
merge_with_error_impl_take_error_message!(InvalidSimilarRankingScoreThreshold);
|
merge_with_error_impl_take_error_message!(InvalidSimilarRankingScoreThreshold);
|
||||||
merge_with_error_impl_take_error_message!(InvalidSimilarId);
|
merge_with_error_impl_take_error_message!(InvalidSimilarId);
|
||||||
// merge_with_error_impl_take_error_message!(InvalidRenderTemplate);
|
|
||||||
// merge_with_error_impl_take_error_message!(InvalidRenderTemplateId);
|
|
||||||
// merge_with_error_impl_take_error_message!(InvalidRenderTemplateInline);
|
|
||||||
|
@ -657,24 +657,6 @@ impl fmt::Display for deserr_codes::InvalidNetworkSearchApiKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for deserr_codes::InvalidRenderTemplate {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "the value of `searchApiKey` is invalid, expected a string.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for deserr_codes::InvalidRenderTemplateId {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "the value of `searchApiKey` is invalid, expected a string.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for deserr_codes::InvalidRenderTemplateInline {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "the value of `searchApiKey` is invalid, expected a string.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! internal_error {
|
macro_rules! internal_error {
|
||||||
($target:ty : $($other:path), *) => {
|
($target:ty : $($other:path), *) => {
|
||||||
|
@ -133,14 +133,12 @@ pub fn extract_token_from_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Policy {
|
pub trait Policy: Sized {
|
||||||
fn authenticate(
|
fn authenticate(
|
||||||
auth: Data<AuthController>,
|
auth: Data<AuthController>,
|
||||||
token: &str,
|
token: &str,
|
||||||
index: Option<&str>,
|
index: Option<&str>,
|
||||||
) -> Result<AuthFilter, policies::AuthError>
|
) -> Result<AuthFilter, policies::AuthError>;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod policies {
|
pub mod policies {
|
||||||
@ -352,7 +350,8 @@ pub mod policies {
|
|||||||
) -> Result<AuthFilter, AuthError> {
|
) -> Result<AuthFilter, AuthError> {
|
||||||
let filter_a = ActionPolicy::<A>::authenticate(auth.clone(), token, index)?;
|
let filter_a = ActionPolicy::<A>::authenticate(auth.clone(), token, index)?;
|
||||||
let _filter_b = ActionPolicy::<B>::authenticate(auth, token, index)?;
|
let _filter_b = ActionPolicy::<B>::authenticate(auth, token, index)?;
|
||||||
|
// There is no point merging the filters here.
|
||||||
|
// Since they originate from the same API key, they will hold the same information.
|
||||||
Ok(filter_a)
|
Ok(filter_a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ use crate::routes::indexes::render_analytics::RenderAggregator;
|
|||||||
#[openapi(
|
#[openapi(
|
||||||
paths(render_post),
|
paths(render_post),
|
||||||
tags((
|
tags((
|
||||||
name = "Render templates",
|
name = "Render documents",
|
||||||
description = "The /render route allows rendering templates used by Meilisearch.",
|
description = "The /render route allows rendering templates used by Meilisearch.",
|
||||||
external_docs(url = "https://www.meilisearch.com/docs/reference/api/render"),
|
external_docs(url = "https://www.meilisearch.com/docs/reference/api/render"),
|
||||||
)),
|
)),
|
||||||
@ -45,34 +45,35 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(render_post))));
|
cfg.service(web::resource("").route(web::post().to(SeqHandler(render_post))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render templates with POST
|
/// Render documents with POST
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
path = "{indexUid}/render",
|
path = "{indexUid}/render",
|
||||||
tag = "Render templates",
|
tag = "Render documents",
|
||||||
security(("Bearer" = ["settings.get", "settings.*", "*.get", "*"])),
|
security(("Bearer" = ["settings.get,documents.get", "*.get", "*"])),
|
||||||
params(("indexUid" = String, Path, example = "movies", description = "Index Unique Identifier", nullable = false)),
|
params(("indexUid" = String, Path, example = "movies", description = "Index Unique Identifier", nullable = false)),
|
||||||
request_body = RenderQuery,
|
request_body = RenderQuery,
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "The rendered result is returned", body = RenderResult, content_type = "application/json", example = json!(
|
(status = 200, description = "The rendered result is returned along with the template", body = RenderResult, content_type = "application/json", example = json!(
|
||||||
{
|
{
|
||||||
|
"template": "{{ doc.breed }} called {{ doc.name }}",
|
||||||
"rendered": "A Jack Russell called Iko"
|
"rendered": "A Jack Russell called Iko"
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
(status = 404, description = "Template or document not found", body = ResponseError, content_type = "application/json", example = json!(
|
(status = 404, description = "Template or document not found", body = ResponseError, content_type = "application/json", example = json!(
|
||||||
{
|
{
|
||||||
"message": "Index `movies` not found.", // TODO
|
"message": "Document with ID `9999` not found.",
|
||||||
"code": "index_not_found",
|
"code": "render_document_not_found",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#index_not_found"
|
"link": "https://docs.meilisearch.com/errors#render_document_not_found"
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
(status = 400, description = "Template couldn't be rendered", body = ResponseError, content_type = "application/json", example = json!(
|
(status = 400, description = "Parameters are incorrect", body = ResponseError, content_type = "application/json", example = json!(
|
||||||
{
|
{
|
||||||
"message": "The Authorization header is missing. It must use the bearer authorization method.", // TODO
|
"message": "Indexing fragment `mistake` does not exist for embedder `rest`.\n Hint: Available indexing fragments are `basic`, `withBreed`.",
|
||||||
"code": "missing_authorization_header",
|
"code": "invalid_render_template_id",
|
||||||
"type": "auth",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
|
"link": "https://docs.meilisearch.com/errors#invalid_render_template_id"
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
@ -91,7 +92,7 @@ pub async fn render_post(
|
|||||||
let index = index_scheduler.index(&index_uid)?;
|
let index = index_scheduler.index(&index_uid)?;
|
||||||
|
|
||||||
let query = params.into_inner();
|
let query = params.into_inner();
|
||||||
debug!(parameters = ?query, "Render template");
|
debug!(parameters = ?query, "Render document");
|
||||||
|
|
||||||
let mut aggregate = RenderAggregator::from_query(&query);
|
let mut aggregate = RenderAggregator::from_query(&query);
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ pub async fn render_post(
|
|||||||
|
|
||||||
let result = result?;
|
let result = result?;
|
||||||
|
|
||||||
debug!(returns = ?result, "Render template");
|
debug!(returns = ?result, "Render document");
|
||||||
Ok(HttpResponse::Ok().json(result))
|
Ok(HttpResponse::Ok().json(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user