mylloon.fr/src/routes/contact.rs

86 lines
2.9 KiB
Rust
Raw Normal View History

use actix_web::{get, routes, web, HttpRequest, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content;
use crate::{
config::Config,
misc::utils::get_url,
template::{Infos, NavBar},
};
#[get("/contact")]
async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(build_page(
config.get_ref().to_owned(),
get_url(req.connection_info()),
))
}
#[routes]
#[get("/contact/{service}")]
#[get("/contact/{service}/{scope}")]
async fn service_redirection(req: HttpRequest) -> impl Responder {
let info = req.match_info();
let find_redirection = match info.query("service") {
/* Socials links */
"twitter" => Some("https://twitter.com/Mylloon".to_owned()),
"mastodon" => Some("https://piaille.fr/@mylloon".to_owned()),
2023-10-19 01:52:22 +02:00
"bluesky" => Some("https://bsky.app/profile/mylloon.fr".to_owned()),
"discord" => match info.get("scope") {
Some("user") => Some("https://discord.com/users/158260864623968257/".to_owned()),
Some("guild") => Some("https://discord.gg/Z5ePxH4".to_owned()),
_ => None,
},
"reddit" => Some("https://www.reddit.com/user/mylloon".to_owned()),
"instagram" => Some("https://www.instagram.com/mylloon/".to_owned()),
"kitsu" => Some("https://kitsu.io/users/Mylloon/library?status=completed".to_owned()),
"steam" => Some("https://steamcommunity.com/id/mylloon/".to_owned()),
"youtube" => Some("https://www.youtube.com/c/Mylloon".to_owned()),
"twitch" => Some("https://www.twitch.tv/mylloon".to_owned()),
/* Forges */
"github" => Some("https://github.com/Mylloon".to_owned()),
"gitlab" => Some("https://gitlab.com/Mylloon".to_owned()),
"codeberg" => Some("https://codeberg.org/Mylloon".to_owned()),
"forgejo" => Some("https://git.mylloon.fr/Anri".to_owned()),
/* Others */
"keyoxide" => {
Some("https://keyoxide.org/27024A99057E58B8087A5022A82D63DFF8D1317F".to_owned())
}
_ => None,
};
if let Some(redirection) = find_redirection {
// Redirect to the desired service
actix_web::web::Redirect::to(redirection)
} else {
// By default, returns to the contact page
actix_web::web::Redirect::to("/contact")
}
}
#[derive(Content, Debug)]
struct NetworksTemplate {
navbar: NavBar,
}
#[once(time = 60)]
fn build_page(config: Config, url: String) -> String {
config.tmpl.render(
"contact.html",
NetworksTemplate {
navbar: NavBar {
contact: true,
..NavBar::default()
},
},
Infos {
page_title: Some("Contacts".into()),
page_desc: Some(format!("Réseaux d'{}", config.fc.name.unwrap_or_default())),
page_kw: None,
url,
},
)
}