mylloon.fr/src/routes/agreements.rs

100 lines
2.6 KiB
Rust
Raw Normal View History

use crate::{config::Config, utils::misc::get_url, template::InfosPage};
use actix_web::{get, http::header::ContentType, routes, web, 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")]
2024-06-17 15:56:57 +02:00
pub async fn security(config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok()
.content_type(ContentType::plaintext())
.body(build_securitytxt(config.get_ref().to_owned()))
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 {
2023-10-24 11:50:30 +02:00
url: String,
2023-02-08 22:14:57 +01:00
contact: String,
pref_lang: String,
}
2023-04-11 10:45:25 +02:00
#[once(time = 60)]
2023-10-24 11:50:30 +02:00
fn build_securitytxt(config: Config) -> String {
2023-04-09 19:26:20 +02:00
config.tmpl.render(
2023-04-09 19:02:06 +02:00
"security.txt",
SecurityTemplate {
2023-10-24 11:50:30 +02:00
url: format!("{}/.well-known/security.txt", get_url(config.fc.clone())),
2023-04-09 19:02:06 +02:00
contact: config.fc.mail.unwrap_or_default(),
pref_lang: config.fc.lang.unwrap_or_default(),
},
2024-05-28 20:26:58 +02:00
InfosPage::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")]
2024-06-17 15:56:57 +02:00
pub async fn humans(config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok()
.content_type(ContentType::plaintext())
.body(build_humanstxt(config.get_ref().to_owned()))
2023-04-28 12:19:46 +02:00
}
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
},
2024-05-28 20:26:58 +02:00
InfosPage::default(),
2023-04-28 12:19:46 +02:00
)
2023-02-08 22:22:20 +01:00
}
#[get("/robots.txt")]
2024-06-17 15:56:57 +02:00
pub async fn robots() -> impl Responder {
HttpResponse::Ok()
.content_type(ContentType::plaintext())
.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
}
2024-01-25 17:46:00 +01:00
#[get("/app.webmanifest")]
2024-06-17 15:56:57 +02:00
pub async fn webmanifest(config: web::Data<Config>) -> impl Responder {
2024-01-25 17:46:00 +01:00
HttpResponse::Ok()
.content_type(ContentType("application/manifest+json".parse().unwrap()))
.body(build_webmanifest(config.get_ref().to_owned()))
}
#[derive(Content, Debug)]
struct WebManifestTemplate {
name: String,
description: String,
url: String,
}
#[once(time = 60)]
fn build_webmanifest(config: Config) -> String {
config.tmpl.render(
"app.webmanifest",
WebManifestTemplate {
name: config.fc.clone().app_name.unwrap(),
description: "Easy WebPage generator".to_owned(),
url: get_url(config.fc),
},
2024-05-28 20:26:58 +02:00
InfosPage::default(),
2024-01-25 17:46:00 +01:00
)
2023-02-08 22:22:20 +01:00
}