use crate::{config::Config, misc::utils::get_url, template::Infos}; use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder}; use cached::proc_macro::once; use ramhorns::Content; #[routes] #[get("/.well-known/security.txt")] #[get("/security.txt")] async fn security(req: HttpRequest, config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_securitytxt( config.get_ref().to_owned(), get_url(req.connection_info()), )) } #[derive(Content, Debug)] struct SecurityTemplate { contact: String, pref_lang: String, url: String, } #[once(time = 60)] fn build_securitytxt(config: Config, url: String) -> String { config.tmpl.render( "security.txt", SecurityTemplate { contact: config.fc.mail.unwrap_or_default(), pref_lang: config.fc.lang.unwrap_or_default(), url: format!("{}/.well-known/security.txt", url), }, Infos::default(), ) } #[get("/humans.txt")] async fn humans(config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_humanstxt(config.get_ref().to_owned())) } #[derive(Content, Debug)] struct HumansTemplate { contact: String, lang: String, name: String, } #[once(time = 60)] fn build_humanstxt(config: Config) -> String { config.tmpl.render( "humans.txt", HumansTemplate { contact: config.fc.mail.unwrap_or_default(), lang: config.fc.lang.unwrap_or_default(), name: config.fc.fullname.unwrap_or_default(), }, Infos::default(), ) } #[get("/robots.txt")] async fn robots() -> impl Responder { HttpResponse::Ok().body(build_robotstxt()) } #[once(time = 60)] fn build_robotstxt() -> String { "User-agent: * Allow: /".into() } #[get("/sitemap.xml")] async fn sitemap() -> impl Responder { // TODO actix_web::web::Redirect::to("/") }