mylloon.fr/src/routes/agreements.rs

76 lines
1.9 KiB
Rust
Raw Normal View History

use crate::{config::Config, misc::utils::get_url, template::Infos};
use actix_web::{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")]
async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(build_securitytxt(
2023-04-24 12:18:21 +02:00
config.get_ref().to_owned(),
get_url(req.connection_info()),
2023-02-16 21:44:00 +01:00
))
2023-02-08 22:14:57 +01:00
}
2023-05-02 13:34:43 +02:00
#[derive(Content, Debug)]
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, url: String) -> 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", url),
2023-04-09 19:02:06 +02:00
},
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")]
async fn humans(config: web::Data<Config>) -> impl Responder {
2023-04-28 12:19:46 +02:00
HttpResponse::Ok().body(build_humanstxt(config.get_ref().to_owned()))
}
2023-05-02 13:34:43 +02:00
#[derive(Content, Debug)]
2023-04-28 12:19:46 +02:00
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(),
2023-04-28 12:49:48 +02:00
name: config.fc.fullname.unwrap_or_default(),
2023-04-28 12:19:46 +02:00
},
Infos::default(),
)
2023-02-08 22:22:20 +01:00
}
#[get("/robots.txt")]
async fn robots() -> impl Responder {
HttpResponse::Ok().body(build_robotstxt())
2023-02-09 12:01:35 +01:00
}
2023-10-21 23:08:03 +02:00
#[once]
fn build_robotstxt() -> String {
"User-agent: * Allow: /".into()
2023-02-08 22:22:20 +01:00
}
#[get("/sitemap.xml")]
async fn sitemap() -> impl Responder {
2023-02-08 22:22:20 +01:00
// TODO
actix_web::web::Redirect::to("/")
}