78 lines
2 KiB
Rust
78 lines
2 KiB
Rust
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
|
use actix_web::{get, http::header::ContentType, routes, web, HttpResponse, Responder};
|
|
use cached::proc_macro::once;
|
|
use ramhorns::Content;
|
|
|
|
#[routes]
|
|
#[get("/.well-known/security.txt")]
|
|
#[get("/security.txt")]
|
|
async fn security(config: web::Data<Config>) -> impl Responder {
|
|
HttpResponse::Ok()
|
|
.content_type(ContentType::plaintext())
|
|
.body(build_securitytxt(config.get_ref().to_owned()))
|
|
}
|
|
|
|
#[derive(Content, Debug)]
|
|
struct SecurityTemplate {
|
|
url: String,
|
|
contact: String,
|
|
pref_lang: String,
|
|
}
|
|
|
|
#[once(time = 60)]
|
|
fn build_securitytxt(config: Config) -> String {
|
|
config.tmpl.render(
|
|
"security.txt",
|
|
SecurityTemplate {
|
|
url: format!("{}/.well-known/security.txt", get_url(config.fc.clone())),
|
|
contact: config.fc.mail.unwrap_or_default(),
|
|
pref_lang: config.fc.lang.unwrap_or_default(),
|
|
},
|
|
Infos::default(),
|
|
)
|
|
}
|
|
|
|
#[get("/humans.txt")]
|
|
async fn humans(config: web::Data<Config>) -> impl Responder {
|
|
HttpResponse::Ok()
|
|
.content_type(ContentType::plaintext())
|
|
.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()
|
|
.content_type(ContentType::plaintext())
|
|
.body(build_robotstxt())
|
|
}
|
|
|
|
#[once]
|
|
fn build_robotstxt() -> String {
|
|
"User-agent: * Allow: /".into()
|
|
}
|
|
|
|
#[get("/sitemap.xml")]
|
|
async fn sitemap() -> impl Responder {
|
|
// TODO
|
|
actix_web::web::Redirect::to("/")
|
|
}
|