2023-10-15 20:58:20 +02:00
|
|
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
2023-04-11 10:45:25 +02:00
|
|
|
use cached::proc_macro::once;
|
2023-10-15 20:58:20 +02:00
|
|
|
use ramhorns::Content;
|
2023-02-08 22:27:40 +01:00
|
|
|
|
2023-10-15 20:58:20 +02:00
|
|
|
use crate::{
|
|
|
|
config::Config,
|
|
|
|
misc::utils::get_url,
|
|
|
|
template::{Infos, NavBar},
|
|
|
|
};
|
2023-02-09 11:19:53 +01:00
|
|
|
|
2023-10-15 20:58:20 +02:00
|
|
|
pub async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
|
|
|
HttpResponse::NotFound().body(build_page(
|
|
|
|
config.get_ref().to_owned(),
|
|
|
|
get_url(req.connection_info()),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Content, Debug)]
|
|
|
|
struct NotFoundTemplate {
|
|
|
|
navbar: NavBar,
|
|
|
|
www: String,
|
|
|
|
onion: Option<String>,
|
2023-02-09 10:55:49 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-10-15 20:58:20 +02:00
|
|
|
fn build_page(config: Config, url: String) -> String {
|
|
|
|
config.tmpl.render(
|
|
|
|
"404.html",
|
|
|
|
NotFoundTemplate {
|
|
|
|
navbar: NavBar::default(),
|
|
|
|
www: url,
|
|
|
|
onion: config.fc.onion,
|
|
|
|
},
|
|
|
|
Infos {
|
|
|
|
page_desc: Some("Une page perdu du web".into()),
|
|
|
|
..Infos::default()
|
|
|
|
},
|
|
|
|
)
|
2023-02-08 22:27:40 +01:00
|
|
|
}
|