fix content type
This commit is contained in:
parent
25931b97cf
commit
a14bf93302
2 changed files with 19 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use maud::{html, PreEscaped, DOCTYPE};
|
use maud::{html, PreEscaped, DOCTYPE};
|
||||||
|
use rocket::http::ContentType;
|
||||||
use rocket::request::{FromRequest, Outcome, Request};
|
use rocket::request::{FromRequest, Outcome, Request};
|
||||||
|
|
||||||
pub enum RequestClient {
|
pub enum RequestClient {
|
||||||
|
@ -37,7 +38,7 @@ pub async fn build_site(
|
||||||
disable_color: bool,
|
disable_color: bool,
|
||||||
shadow: bool,
|
shadow: bool,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
) -> String {
|
) -> (ContentType, String) {
|
||||||
let mut c_class = "bg-dark text-white justify-content-center text-center".to_string();
|
let mut c_class = "bg-dark text-white justify-content-center text-center".to_string();
|
||||||
let mut c_style = String::new();
|
let mut c_style = String::new();
|
||||||
let mut g_style = "a {text-decoration: none; font-weight: bold; color: white}".to_string();
|
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 {
|
pub fn build_site_from_body(title: &str, body: &str) -> String {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use maud::{html, PreEscaped};
|
use maud::{html, PreEscaped};
|
||||||
|
use rocket::http::ContentType;
|
||||||
use rocket::{form::Form, get, post, response::Redirect, uri, FromForm, State};
|
use rocket::{form::Form, get, post, response::Redirect, uri, FromForm, State};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ pub async fn message_post(msg: Form<MessageForm>, config: &State<config::Config>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/message")]
|
#[get("/message")]
|
||||||
pub async fn message_page(config: &State<config::Config>) -> String {
|
pub async fn message_page(config: &State<config::Config>) -> (ContentType, String) {
|
||||||
let post_uri = uri!(message_post).to_string();
|
let post_uri = uri!(message_post).to_string();
|
||||||
|
|
||||||
let resp = html! {
|
let resp = html! {
|
||||||
|
@ -39,7 +40,10 @@ pub async fn message_page(config: &State<config::Config>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/mirrors.txt")]
|
#[get("/mirrors.txt")]
|
||||||
pub async fn mirrors(r: RequestClient, config: &State<config::Config>) -> Option<String> {
|
pub async fn mirrors(
|
||||||
|
r: RequestClient,
|
||||||
|
config: &State<config::Config>,
|
||||||
|
) -> Option<(ContentType, String)> {
|
||||||
if let Ok(mirror_file) = std::fs::File::open("./config/mirrors.txt") {
|
if let Ok(mirror_file) = std::fs::File::open("./config/mirrors.txt") {
|
||||||
let content = std::io::read_to_string(mirror_file).ok()?;
|
let content = std::io::read_to_string(mirror_file).ok()?;
|
||||||
if matches!(r, RequestClient::Browser) {
|
if matches!(r, RequestClient::Browser) {
|
||||||
|
@ -53,14 +57,17 @@ pub async fn mirrors(r: RequestClient, config: &State<config::Config>) -> Option
|
||||||
|
|
||||||
return Some(build_site(resp.into_string(), "Mirrors", false, true, config).await);
|
return Some(build_site(resp.into_string(), "Mirrors", false, true, config).await);
|
||||||
}
|
}
|
||||||
return Some(content);
|
return Some((ContentType::Plain, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/public_key")]
|
#[get("/public_key")]
|
||||||
pub async fn public_key(r: RequestClient, config: &State<config::Config>) -> Option<String> {
|
pub async fn public_key(
|
||||||
|
r: RequestClient,
|
||||||
|
config: &State<config::Config>,
|
||||||
|
) -> Option<(ContentType, String)> {
|
||||||
if matches!(r, RequestClient::Browser) {
|
if matches!(r, RequestClient::Browser) {
|
||||||
let host = config.base_url();
|
let host = config.base_url();
|
||||||
let key = std::io::read_to_string(
|
let key = std::io::read_to_string(
|
||||||
|
@ -90,7 +97,7 @@ pub async fn public_key(r: RequestClient, config: &State<config::Config>) -> Opt
|
||||||
|
|
||||||
if let Ok(key_f) = std::fs::File::open("./config/pub.key") {
|
if let Ok(key_f) = std::fs::File::open("./config/pub.key") {
|
||||||
if let Ok(key_data) = std::io::read_to_string(key_f) {
|
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("/")]
|
#[get("/")]
|
||||||
pub async fn index(conf: &State<config::Config>) -> String {
|
pub async fn index(conf: &State<config::Config>) -> (ContentType, String) {
|
||||||
let information_block = build_information_block(conf);
|
let information_block = build_information_block(conf);
|
||||||
let contact_block = build_contact_block(conf);
|
let contact_block = build_contact_block(conf);
|
||||||
let donation_block = build_donation_block(conf);
|
let donation_block = build_donation_block(conf);
|
||||||
|
|
Loading…
Add table
Reference in a new issue