mylloon.fr/src/routes/agreements.rs
2023-02-09 12:01:35 +01:00

52 lines
1.3 KiB
Rust

use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder};
use askama::Template;
use std::net::SocketAddr;
use crate::config::Config;
#[routes]
#[get("/.well-known/security.txt")]
#[get("/security.txt")]
pub async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_security(config.get_ref().clone(), req.peer_addr()))
}
#[derive(Template)]
#[template(path = "../templates/security.txt")]
struct SecurityTemplate {
contact: String,
pref_lang: String,
url: String,
}
fn get_security(config: Config, addr: Option<SocketAddr>) -> String {
let data = SecurityTemplate {
contact: config.mail.unwrap_or_default(),
pref_lang: config.lang.unwrap_or_default(),
url: format!("{}/.well-known/security.txt", addr.unwrap().ip()),
};
data.render().unwrap()
}
#[get("/humans.txt")]
pub async fn humans() -> impl Responder {
// TODO, see https://humanstxt.org/humans.txt
actix_web::web::Redirect::to("/")
}
#[get("/robots.txt")]
pub async fn robots() -> impl Responder {
HttpResponse::Ok().body(get_robots())
}
fn get_robots() -> String {
// TODO, see https://www.robotstxt.org/orig.html
"User-agent: * Allow: /".to_string()
}
#[get("/sitemap.xml")]
pub async fn sitemap() -> impl Responder {
// TODO
actix_web::web::Redirect::to("/")
}