mylloon.fr/src/routes/agreements.rs

62 lines
1.6 KiB
Rust
Raw Normal View History

2023-04-11 10:03:22 +02:00
use crate::{config::Config, template::Infos};
2023-02-16 21:44:00 +01:00
use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
2023-04-11 10:45:25 +02:00
use cached::proc_macro::once;
2023-04-09 19:02:06 +02:00
use ramhorns::Content;
2023-02-08 22:14:57 +01:00
#[routes]
#[get("/.well-known/security.txt")]
#[get("/security.txt")]
pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(build_securitytxt(
2023-02-16 21:44:00 +01:00
config.get_ref().clone(),
req.connection_info().to_owned(),
))
2023-02-08 22:14:57 +01:00
}
2023-04-09 19:02:06 +02:00
#[derive(Content)]
2023-02-08 22:14:57 +01:00
struct SecurityTemplate {
contact: String,
pref_lang: String,
url: String,
}
2023-04-11 10:45:25 +02:00
#[once(time = 60)]
fn build_securitytxt(config: Config, info: ConnectionInfo) -> String {
2023-04-09 19:26:20 +02:00
config.tmpl.render(
2023-04-09 19:02:06 +02:00
"security.txt",
SecurityTemplate {
contact: config.fc.mail.unwrap_or_default(),
pref_lang: config.fc.lang.unwrap_or_default(),
url: format!(
"{}://{}/.well-known/security.txt",
info.scheme(),
info.host()
),
},
2023-04-11 10:03:22 +02:00
Infos::default(),
2023-04-09 19:02:06 +02:00
)
2023-02-08 22:14:57 +01:00
}
2023-02-08 22:22:20 +01:00
#[get("/humans.txt")]
pub async fn humans() -> impl Responder {
2023-02-09 12:01:35 +01:00
// TODO, see https://humanstxt.org/humans.txt
2023-02-08 22:22:20 +01:00
actix_web::web::Redirect::to("/")
}
#[get("/robots.txt")]
pub async fn robots() -> impl Responder {
HttpResponse::Ok().body(build_robotstxt())
2023-02-09 12:01:35 +01:00
}
2023-04-11 10:45:25 +02:00
#[once(time = 60)]
fn build_robotstxt() -> String {
2023-02-09 12:01:35 +01:00
// TODO, see https://www.robotstxt.org/orig.html
2023-04-21 19:22:00 +02:00
"User-agent: * Allow: /".to_owned()
2023-02-08 22:22:20 +01:00
}
#[get("/sitemap.xml")]
pub async fn sitemap() -> impl Responder {
// TODO
actix_web::web::Redirect::to("/")
}