📝 Update the guides to the latest PageTop API
This commit is contained in:
parent
c0e86f132d
commit
b99daec9a6
8 changed files with 27 additions and 28 deletions
|
|
@ -24,7 +24,7 @@ async fn plot(
|
|||
web::Path(code): web::Path<String>,
|
||||
) -> Result<Markup, ErrorPage> {
|
||||
let Some((_, holder)) = PLOTS.iter().find(|(c, _)| *c == code) else {
|
||||
return Err(ErrorPage::NotFound(Some(request)));
|
||||
return Err(ErrorPage::NotFound(request));
|
||||
};
|
||||
let holder = holder.to_string();
|
||||
Page::new(request)
|
||||
|
|
@ -47,9 +47,8 @@ Elige la variante por lo que ha pasado:
|
|||
| `ErrorPage::ServiceUnavailable` | 503 | El servicio no puede atender ahora (mantenimiento, carga) |
|
||||
| `ErrorPage::GatewayTimeout` | 504 | Un servicio externo no ha respondido a tiempo |
|
||||
|
||||
Pásale siempre la petición (`Some(request)`): con ella la página de error sale en el idioma del
|
||||
visitante y sabe quién es, por ejemplo para mostrar su menú de cuenta. Con `None` también se
|
||||
muestra, pero sin esos datos.
|
||||
Se le pasa la petición: con ella la página de error sale en el idioma del visitante y sabe quién
|
||||
es, por ejemplo para mostrar su menú de cuenta.
|
||||
|
||||
Las rutas que no existen no necesitan nada: PageTop responde por sí solo con la misma página 404.
|
||||
|
||||
|
|
@ -63,7 +62,7 @@ falla. Conviértelo con `map_err()` y sigue usando `?`:
|
|||
async fn report(request: HttpRequest) -> Result<Markup, ErrorPage> {
|
||||
let text = std::fs::read_to_string("data/report.txt").map_err(|err| {
|
||||
trace::error!(%err, "Cannot read the report");
|
||||
ErrorPage::InternalError(Some(request.clone()))
|
||||
ErrorPage::InternalError(request.clone())
|
||||
})?;
|
||||
|
||||
Page::new(request)
|
||||
|
|
@ -194,7 +193,7 @@ async fn plot(
|
|||
web::Path(code): web::Path<String>,
|
||||
) -> Result<Markup, ErrorPage> {
|
||||
let Some((_, holder)) = PLOTS.iter().find(|(c, _)| *c == code) else {
|
||||
return Err(ErrorPage::NotFound(Some(request)));
|
||||
return Err(ErrorPage::NotFound(request));
|
||||
};
|
||||
let holder = holder.to_string();
|
||||
Page::new(request)
|
||||
|
|
@ -207,7 +206,7 @@ async fn plot(
|
|||
async fn report(request: HttpRequest) -> Result<Markup, ErrorPage> {
|
||||
let text = std::fs::read_to_string("data/report.txt").map_err(|err| {
|
||||
trace::error!(%err, "Cannot read the report");
|
||||
ErrorPage::InternalError(Some(request.clone()))
|
||||
ErrorPage::InternalError(request.clone())
|
||||
})?;
|
||||
|
||||
Page::new(request)
|
||||
|
|
@ -256,7 +255,7 @@ También puedes comprobarlo en una prueba (ve [Probar rutas y componentes](testi
|
|||
# web::Path(code): web::Path<String>,
|
||||
# ) -> Result<Markup, ErrorPage> {
|
||||
# let Some((_, holder)) = PLOTS.iter().find(|(c, _)| *c == code) else {
|
||||
# return Err(ErrorPage::NotFound(Some(request)));
|
||||
# return Err(ErrorPage::NotFound(request));
|
||||
# };
|
||||
# let holder = holder.to_string();
|
||||
# Page::new(request)
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ base_url = "https://garden.example.com"
|
|||
# .with_to(gardener.email)
|
||||
# .send()
|
||||
# .await
|
||||
# .map_err(|_| ErrorPage::InternalError(Some(request)))?;
|
||||
# .map_err(|_| ErrorPage::InternalError(request))?;
|
||||
# Ok(Redirect::see_other(cx.route("/harvest")))
|
||||
# }
|
||||
use pagetop_mail::outbox;
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ async fn view(
|
|||
web::Path(id): web::Path<u32>,
|
||||
) -> Result<Markup, ErrorPage> {
|
||||
if id == 0 {
|
||||
return Err(ErrorPage::NotFound(Some(request)));
|
||||
return Err(ErrorPage::NotFound(request));
|
||||
}
|
||||
Page::new(request).render().await
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ async fn upload(request: HttpRequest, multipart: web::Multipart) -> Result<Respo
|
|||
Ok(sent) => sent,
|
||||
// Too large, a type not allowed...: shows the form again with the reason.
|
||||
Err(err) if err.is_client_error() => return show_form(request, err.message()).await,
|
||||
Err(_) => return Err(ErrorPage::InternalError(Some(request))),
|
||||
Err(_) => return Err(ErrorPage::InternalError(request)),
|
||||
};
|
||||
let Some(photo) = sent.file("photo") else {
|
||||
return show_form(request, Lc::n("Choose a photo to upload.")).await;
|
||||
|
|
@ -133,15 +133,15 @@ async fn photo(
|
|||
) -> Result<Response, ErrorPage> {
|
||||
// Check the permissions here, as in any other handler...
|
||||
let Some((path, original_name)) = find_photo(index) else {
|
||||
return Err(ErrorPage::NotFound(Some(request)));
|
||||
return Err(ErrorPage::NotFound(request));
|
||||
};
|
||||
web::Download::new(path)
|
||||
.with_file_name(original_name)
|
||||
.serve(&request)
|
||||
.await
|
||||
.map_err(|err| match err {
|
||||
web::UploadError::NotFound(_) => ErrorPage::NotFound(Some(request)),
|
||||
_ => ErrorPage::InternalError(Some(request)),
|
||||
web::UploadError::NotFound(_) => ErrorPage::NotFound(request),
|
||||
_ => ErrorPage::InternalError(request),
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
@ -301,7 +301,7 @@ async fn upload(request: HttpRequest, multipart: web::Multipart) -> Result<Respo
|
|||
let sent = match photo_upload().receive::<PhotoData>(multipart).await {
|
||||
Ok(sent) => sent,
|
||||
Err(err) if err.is_client_error() => return show_form(request, err.message()).await,
|
||||
Err(_) => return Err(ErrorPage::InternalError(Some(request))),
|
||||
Err(_) => return Err(ErrorPage::InternalError(request)),
|
||||
};
|
||||
let Some(file) = sent.file("photo") else {
|
||||
return show_form(request, Lc::n("Choose a photo to upload.")).await;
|
||||
|
|
@ -329,15 +329,15 @@ async fn photo(
|
|||
.get(index)
|
||||
.map(|photo| (photo.path.clone(), photo.original_name.clone()));
|
||||
let Some((path, original_name)) = found else {
|
||||
return Err(ErrorPage::NotFound(Some(request)));
|
||||
return Err(ErrorPage::NotFound(request));
|
||||
};
|
||||
web::Download::new(path)
|
||||
.with_file_name(original_name)
|
||||
.serve(&request)
|
||||
.await
|
||||
.map_err(|err| match err {
|
||||
web::UploadError::NotFound(_) => ErrorPage::NotFound(Some(request)),
|
||||
_ => ErrorPage::InternalError(Some(request)),
|
||||
web::UploadError::NotFound(_) => ErrorPage::NotFound(request),
|
||||
_ => ErrorPage::InternalError(request),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ otro lugar en `config/test.toml` (por ejemplo, `"target/test-uploads"`):
|
|||
# let sent = match photo_upload().receive::<PhotoData>(multipart).await {
|
||||
# Ok(sent) => sent,
|
||||
# Err(err) if err.is_client_error() => return show_form(request, err.message()).await,
|
||||
# Err(_) => return Err(ErrorPage::InternalError(Some(request))),
|
||||
# Err(_) => return Err(ErrorPage::InternalError(request)),
|
||||
# };
|
||||
# let Some(file) = sent.file("photo") else {
|
||||
# return show_form(request, Lc::n("Choose a photo to upload.")).await;
|
||||
|
|
@ -421,13 +421,13 @@ otro lugar en `config/test.toml` (por ejemplo, `"target/test-uploads"`):
|
|||
# .get(index)
|
||||
# .map(|photo| (photo.path.clone(), photo.original_name.clone()));
|
||||
# let Some((path, original_name)) = found else {
|
||||
# return Err(ErrorPage::NotFound(Some(request)));
|
||||
# return Err(ErrorPage::NotFound(request));
|
||||
# };
|
||||
# web::Download::new(path)
|
||||
# .with_file_name(original_name)
|
||||
# .serve(&request)
|
||||
# .await
|
||||
# .map_err(|_| ErrorPage::NotFound(Some(request)))
|
||||
# .map_err(|_| ErrorPage::NotFound(request))
|
||||
# }
|
||||
// A submission with a title and one file, as a browser sends it.
|
||||
fn photo_body(file_name: &str, content: &str) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue