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 {
|
pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse {
|
||||||
let first = form.first_name.clone();
|
let first = form.first_name.clone();
|
||||||
let last = form.last_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 filename_noext = format!("{}_{}", first, last);
|
||||||
|
let email_subject = format!("{} {} signed up for mission trip!", first, last);
|
||||||
info!("{first} {last} signed up for mission trip!");
|
info!("{first} {last} signed up for mission trip!");
|
||||||
let email = form.build_email().await;
|
let email = form.build_email().await;
|
||||||
let mut path = String::from("");
|
let mut path = String::from("");
|
||||||
let mut file_exists = false;
|
let mut file_exists = false;
|
||||||
let mut filename = String::from("");
|
let mut filename = String::from("");
|
||||||
info!("{:?}", file_exists);
|
|
||||||
if let Some(file) = form.file.file_name {
|
if let Some(file) = form.file.file_name {
|
||||||
if let Some(ext) = file.rsplit('.').next() {
|
if let Some(ext) = file.rsplit('.').next() {
|
||||||
filename = format!("{}.{}", filename_noext, ext);
|
filename = format!("{}.{}", filename_noext, ext);
|
||||||
|
@ -237,14 +236,13 @@ pub async fn mt_form(MultipartForm(form): MultipartForm<MtForm>) -> HttpResponse
|
||||||
} else {
|
} else {
|
||||||
path = format!("./tmp/{}", file);
|
path = format!("./tmp/{}", file);
|
||||||
}
|
}
|
||||||
// let path = format!("./tmp/{}", file);
|
|
||||||
info!("saving to {}", path);
|
info!("saving to {}", path);
|
||||||
match form.file.file.persist(&path) {
|
match form.file.file.persist(&path) {
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
info!("{:?}", f);
|
|
||||||
if f.metadata().unwrap().len() > 0 {
|
if f.metadata().unwrap().len() > 0 {
|
||||||
file_exists = true;
|
file_exists = true;
|
||||||
}
|
}
|
||||||
|
info!(?f, "File saved successfully");
|
||||||
}
|
}
|
||||||
Err(e) => info!("{:?}: Probably a missing image", e),
|
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 filebody = fs::read(path);
|
||||||
let content_type = ContentType::parse("image/jpg").unwrap();
|
let content_type = ContentType::parse("image/jpg").unwrap();
|
||||||
let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type);
|
let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type);
|
||||||
info!("{:?}", attachment);
|
// info!(?attachment);
|
||||||
MultiPart::mixed()
|
MultiPart::mixed()
|
||||||
.singlepart(SinglePart::html(email.into_string()))
|
.singlepart(SinglePart::html(email.into_string()))
|
||||||
.singlepart(attachment)
|
.singlepart(attachment)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue