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

27
src/routes/upload.rs Normal file
View File

@@ -0,0 +1,27 @@
use rocket::data::{Data, ToByteUnit};
use rocket::response::Redirect;
use std::path::Path;
use crate::models::paste_id::PasteId;
#[post("/", data = "<paste>")]
pub async fn upload(paste: Data<'_>) -> Result<Redirect, std::io::Error> {
let id = PasteId::new(6);
let filename = format!("upload/{id}", id = id);
let filepath = Path::new(&filename);
paste.open(100.mebibytes()).into_file(filepath).await?;
let url = match tree_magic::from_filepath(filepath)
.as_str()
.contains("text")
{
true => format!("/p/{id}", id = id),
false => format!("/{id}", id = id),
};
Ok(Redirect::to(url))
}