refactor
This commit is contained in:
parent
6d55f0ff92
commit
2b903cccda
4 changed files with 398 additions and 357 deletions
741
Cargo.lock
generated
741
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -5,10 +5,10 @@ WORKDIR /app
|
||||||
|
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
FROM debian
|
FROM archlinux
|
||||||
|
|
||||||
RUN apt-get update
|
RUN pacman -Syu --noconfirm
|
||||||
RUN apt-get install -y gnupg ca-certificates
|
RUN pacman -S --noconfirm gnupg ca-certificates openssl-1.1
|
||||||
|
|
||||||
COPY --from=builder /app/target/release/me-site /me-site
|
COPY --from=builder /app/target/release/me-site /me-site
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
pub fn encrypt(msg: String) -> String {
|
pub fn encrypt(msg: &str) -> String {
|
||||||
let pgp = gnupg::GnuPG::new().expect("no gpg");
|
let pgp = gnupg::GnuPG::new().expect("no gpg");
|
||||||
let pub_key = pgp
|
let pub_key = pgp
|
||||||
.import_key(&std::fs::read_to_string("./config/pub.key").expect("key could not be read"))
|
.import_key(&std::fs::read_to_string("./config/pub.key").expect("key could not be read"))
|
||||||
.expect("key import error");
|
.expect("key import error");
|
||||||
pgp.encrypt(&pub_key, &msg).expect("encryption failed")
|
pgp.encrypt(&pub_key, msg).expect("encryption failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_message(msg: String, name: &str) {
|
pub fn save_message(msg: &str, name: &str) {
|
||||||
std::fs::create_dir_all("./data/messages").expect("couldn't create msg dir");
|
std::fs::create_dir_all("./data/messages").expect("couldn't create msg dir");
|
||||||
let time = chrono::offset::Utc::now();
|
let time = chrono::offset::Utc::now();
|
||||||
let time = time.format("%Y-%m-%d.%H-%M").to_string();
|
let time = time.format("%Y-%m-%d.%H-%M").to_string();
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct MessageForm {
|
||||||
#[post("/message")]
|
#[post("/message")]
|
||||||
pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responder {
|
pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responder {
|
||||||
let config: &web::Data<config::Config> = r.app_data().expect("get config failed");
|
let config: &web::Data<config::Config> = r.app_data().expect("get config failed");
|
||||||
crate::msg::save_message(f.message.clone(), &f.msg_name.to_string());
|
crate::msg::save_message(&f.message, &f.msg_name.to_string());
|
||||||
crate::notification::notify(
|
crate::notification::notify(
|
||||||
&format!("New Message from {}", f.msg_name),
|
&format!("New Message from {}", f.msg_name),
|
||||||
"New Message",
|
"New Message",
|
||||||
|
|
Loading…
Add table
Reference in a new issue