refactor: bring in the modules

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain
2021-07-11 03:07:50 +05:30
parent 8a3b29a0ef
commit 9c5a3af128
12 changed files with 145 additions and 118 deletions

22
src/routes/submit.rs Normal file
View File

@@ -0,0 +1,22 @@
use rocket::{form::Form, response::Redirect};
use std::fs;
use crate::models::paste_id::PasteId;
#[derive(FromForm)]
pub struct PasteIdForm {
val: String,
}
#[post("/submit", data = "<paste>")]
pub async fn submit(paste: Form<PasteIdForm>) -> Redirect {
let id = PasteId::new(6);
let filename = format!("upload/{id}", id = id);
let content = paste.into_inner().val;
fs::write(&filename, content).expect("Unable to write to the file");
Redirect::to(format!("/p/{id}", id = id))
}