2023-04-29 14:09:41 +02:00
|
|
|
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")]
|
2023-10-15 20:58:20 +02:00
|
|
|
async fn security(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
2023-04-20 15:43:25 +02:00
|
|
|
HttpResponse::Ok().body(build_securitytxt(
|
2023-04-24 12:18:21 +02:00
|
|
|
config.get_ref().to_owned(),
|
2023-04-29 14:09:41 +02:00
|
|
|
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)]
|
2023-04-29 14:09:41 +02:00
|
|
|
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(),
|
2023-04-29 14:09:41 +02:00
|
|
|
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")]
|
2023-10-15 20:58:20 +02:00
|
|
|
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")]
|
2023-10-15 20:58:20 +02:00
|
|
|
async fn robots() -> impl Responder {
|
2023-04-20 15:43:25 +02:00
|
|
|
HttpResponse::Ok().body(build_robotstxt())
|
2023-02-09 12:01:35 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-04-20 15:43:25 +02:00
|
|
|
fn build_robotstxt() -> String {
|
2023-04-26 12:07:46 +02:00
|
|
|
"User-agent: * Allow: /".into()
|
2023-02-08 22:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/sitemap.xml")]
|
2023-10-15 20:58:20 +02:00
|
|
|
async fn sitemap() -> impl Responder {
|
2023-02-08 22:22:20 +01:00
|
|
|
// TODO
|
|
|
|
actix_web::web::Redirect::to("/")
|
|
|
|
}
|