mylloon.fr/src/routes/agreements.rs

32 lines
882 B
Rust
Raw Normal View History

2023-02-08 22:14:57 +01:00
use std::net::SocketAddr;
use actix_web::{routes, web, HttpRequest, HttpResponse, Responder};
use askama::Template;
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,
}
pub fn get_security(config: Config, addr: Option<SocketAddr>) -> std::string::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()
}