cleanup function for readability
This commit is contained in:
parent
612451cfc9
commit
0afa4175ee
1 changed files with 3 additions and 5 deletions
|
@ -222,14 +222,13 @@ impl MtForm {
|
|||
pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse {
|
||||
let first = form.first_name.clone();
|
||||
let last = form.last_name.clone();
|
||||
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||
let filename_noext = format!("{}_{}", first, last);
|
||||
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||
info!("{first} {last} signed up for mission trip!");
|
||||
let email = form.build_email().await;
|
||||
let mut path = String::from("");
|
||||
let mut file_exists = false;
|
||||
let mut filename = String::from("");
|
||||
info!("{:?}", file_exists);
|
||||
if let Some(file) = form.file.file_name {
|
||||
if let Some(ext) = file.rsplit('.').next() {
|
||||
filename = format!("{}.{}", filename_noext, ext);
|
||||
|
@ -237,14 +236,13 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
|
|||
} else {
|
||||
path = format!("./tmp/{}", file);
|
||||
}
|
||||
// let path = format!("./tmp/{}", file);
|
||||
info!("saving to {}", path);
|
||||
match form.file.file.persist(&path) {
|
||||
Ok(f) => {
|
||||
info!("{:?}", f);
|
||||
if f.metadata().unwrap().len() > 0 {
|
||||
file_exists = true;
|
||||
}
|
||||
info!(?f, "File saved successfully");
|
||||
}
|
||||
Err(e) => info!("{:?}: Probably a missing image", e),
|
||||
}
|
||||
|
@ -254,7 +252,7 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
|
|||
let filebody = fs::read(path);
|
||||
let content_type = ContentType::parse("image/jpg").unwrap();
|
||||
let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type);
|
||||
info!("{:?}", attachment);
|
||||
// info!(?attachment);
|
||||
MultiPart::mixed()
|
||||
.singlepart(SinglePart::html(email.into_string()))
|
||||
.singlepart(attachment)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue