diff --git a/src/pages/html.rs b/src/pages/html.rs index fe3b135..a369458 100644 --- a/src/pages/html.rs +++ b/src/pages/html.rs @@ -1,5 +1,6 @@ use crate::config::Config; use maud::{html, PreEscaped, DOCTYPE}; +use rocket::http::ContentType; use rocket::request::{FromRequest, Outcome, Request}; pub enum RequestClient { @@ -37,7 +38,7 @@ pub async fn build_site( disable_color: bool, shadow: bool, config: &Config, -) -> String { +) -> (ContentType, String) { let mut c_class = "bg-dark text-white justify-content-center text-center".to_string(); let mut c_style = String::new(); let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string(); @@ -64,7 +65,10 @@ pub async fn build_site( }; }; - build_site_from_body(title, &body.into_string()) + ( + ContentType::HTML, + build_site_from_body(title, &body.into_string()), + ) } pub fn build_site_from_body(title: &str, body: &str) -> String { diff --git a/src/pages/index.rs b/src/pages/index.rs index a054a9b..cb7e40f 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -1,5 +1,6 @@ use crate::config; use maud::{html, PreEscaped}; +use rocket::http::ContentType; use rocket::{form::Form, get, post, response::Redirect, uri, FromForm, State}; use serde::{Deserialize, Serialize}; @@ -19,7 +20,7 @@ pub async fn message_post(msg: Form, config: &State } #[get("/message")] -pub async fn message_page(config: &State) -> String { +pub async fn message_page(config: &State) -> (ContentType, String) { let post_uri = uri!(message_post).to_string(); let resp = html! { @@ -39,7 +40,10 @@ pub async fn message_page(config: &State) -> String { } #[get("/mirrors.txt")] -pub async fn mirrors(r: RequestClient, config: &State) -> Option { +pub async fn mirrors( + r: RequestClient, + config: &State, +) -> Option<(ContentType, String)> { if let Ok(mirror_file) = std::fs::File::open("./config/mirrors.txt") { let content = std::io::read_to_string(mirror_file).ok()?; if matches!(r, RequestClient::Browser) { @@ -53,14 +57,17 @@ pub async fn mirrors(r: RequestClient, config: &State) -> Option return Some(build_site(resp.into_string(), "Mirrors", false, true, config).await); } - return Some(content); + return Some((ContentType::Plain, content)); } None } #[get("/public_key")] -pub async fn public_key(r: RequestClient, config: &State) -> Option { +pub async fn public_key( + r: RequestClient, + config: &State, +) -> Option<(ContentType, String)> { if matches!(r, RequestClient::Browser) { let host = config.base_url(); let key = std::io::read_to_string( @@ -90,7 +97,7 @@ pub async fn public_key(r: RequestClient, config: &State) -> Opt if let Ok(key_f) = std::fs::File::open("./config/pub.key") { if let Ok(key_data) = std::io::read_to_string(key_f) { - return Some(key_data); + return Some((ContentType::Plain, key_data)); } } @@ -160,7 +167,7 @@ fn build_donation_block(conf: &config::Config) -> String { } #[get("/")] -pub async fn index(conf: &State) -> String { +pub async fn index(conf: &State) -> (ContentType, String) { let information_block = build_information_block(conf); let contact_block = build_contact_block(conf); let donation_block = build_donation_block(conf);