refactor
This commit is contained in:
parent
37e69a851c
commit
cef45e43a6
6 changed files with 79 additions and 86 deletions
|
@ -16,18 +16,17 @@ pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responde
|
|||
let config: &web::Data<config::Config> = r.app_data().unwrap();
|
||||
crate::msg::save_msg(f.message.clone(), &f.msg_name.to_string());
|
||||
crate::notification::notify(
|
||||
&format!("New Message from {}", f.msg_name.to_string()),
|
||||
&format!("New Message from {}", f.msg_name),
|
||||
"New Message",
|
||||
config.clone(),
|
||||
)
|
||||
.await;
|
||||
return web_base::func::redirect("/message");
|
||||
web_base::func::redirect("/message")
|
||||
}
|
||||
|
||||
#[get("/message")]
|
||||
pub async fn message_page(r: HttpRequest) -> impl Responder {
|
||||
let config: &web::Data<config::Config> = r.app_data().unwrap();
|
||||
let host = web_base::func::get_host(&r);
|
||||
|
||||
let resp = html! {
|
||||
div class="container" style="margin-top: 25px" {
|
||||
|
@ -42,7 +41,7 @@ pub async fn message_page(r: HttpRequest) -> impl Responder {
|
|||
}
|
||||
};
|
||||
|
||||
return pages::html_fn::build_site(resp.into_string(), "Message", false, true, config).await;
|
||||
pages::html_fn::build_site(resp.into_string(), "Message", false, true, config).await
|
||||
}
|
||||
|
||||
#[get("/mirrors.txt")]
|
||||
|
@ -61,13 +60,11 @@ pub async fn mirrors(r: HttpRequest) -> impl Responder {
|
|||
return pages::html_fn::build_site(resp.into_string(), "Mirrors", false, true, config)
|
||||
.await;
|
||||
}
|
||||
let res: HttpResponse<String> = HttpResponse::Ok().message_body(content).unwrap();
|
||||
return res;
|
||||
return HttpResponse::Ok().message_body(content).unwrap();
|
||||
}
|
||||
let res: HttpResponse<String> = HttpResponse::NotFound()
|
||||
HttpResponse::NotFound()
|
||||
.message_body("".to_string())
|
||||
.unwrap();
|
||||
return res;
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[get("/public_key")]
|
||||
|
@ -80,7 +77,7 @@ pub async fn public_key(r: HttpRequest) -> impl Responder {
|
|||
|
||||
let pgp = gnupg::GnuPG::new().unwrap();
|
||||
let key_name = pgp.import_key(&key).unwrap().name;
|
||||
let key = key.replace("\n", "<br>");
|
||||
let key = key.replace('\n', "<br>");
|
||||
|
||||
let resp = html! {
|
||||
div class="container" style="margin-top: 25px" {
|
||||
|
@ -100,23 +97,21 @@ pub async fn public_key(r: HttpRequest) -> impl Responder {
|
|||
}
|
||||
if let Ok(key_f) = std::fs::File::open("./config/pub.key") {
|
||||
if let Ok(key_data) = std::io::read_to_string(key_f) {
|
||||
let res: HttpResponse<String> = HttpResponse::Ok()
|
||||
return HttpResponse::Ok()
|
||||
.insert_header(header::ContentType::plaintext())
|
||||
.message_body(key_data)
|
||||
.unwrap();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
let res: HttpResponse<String> = HttpResponse::NotFound()
|
||||
HttpResponse::NotFound()
|
||||
.message_body("".to_string())
|
||||
.unwrap();
|
||||
return res;
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn build_information_block(conf: &web::Data<config::Config>) -> String {
|
||||
let name = conf.name().unwrap();
|
||||
return html! {
|
||||
html! {
|
||||
div class="container border-dark" style="margin-top: 20px" {
|
||||
img src="/assets/me" height="200" width="200" alt="Me" class="rounded";
|
||||
br;br;
|
||||
|
@ -124,7 +119,7 @@ fn build_information_block(conf: &web::Data<config::Config>) -> String {
|
|||
hr;
|
||||
}
|
||||
}
|
||||
.into_string();
|
||||
.into_string()
|
||||
}
|
||||
|
||||
fn build_contact_block(conf: &web::Data<config::Config>) -> String {
|
||||
|
@ -140,7 +135,7 @@ fn build_contact_block(conf: &web::Data<config::Config>) -> String {
|
|||
false => "".to_string(),
|
||||
};
|
||||
|
||||
return html! {
|
||||
html! {
|
||||
div class="container border-dark" {
|
||||
h1 {
|
||||
span class="bi bi-person-lines-fill" style="vertical-align: middle;";
|
||||
|
@ -152,9 +147,9 @@ fn build_contact_block(conf: &web::Data<config::Config>) -> String {
|
|||
hr;
|
||||
}
|
||||
}
|
||||
.into_string();
|
||||
.into_string()
|
||||
} else {
|
||||
return "".to_string();
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +170,7 @@ fn build_donation_block(conf: &web::Data<config::Config>) -> String {
|
|||
}
|
||||
.into_string()
|
||||
} else {
|
||||
return "".to_string();
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +186,5 @@ pub(crate) async fn index(conf: web::Data<config::Config>) -> impl Responder {
|
|||
{donation_block}
|
||||
"
|
||||
);
|
||||
let r = crate::pages::html_fn::build_site(content, "About Me", false, true, &conf).await;
|
||||
return r;
|
||||
crate::pages::html_fn::build_site(content, "About Me", false, true, &conf).await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue