implement drag and drop

As a consquence of better UX, '/' post handler will now redirect instead
of returning a String.

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain
2021-06-19 06:42:22 +05:30
parent 8ddca50c55
commit 1f84fd28b9
4 changed files with 126 additions and 75 deletions

View File

@@ -50,7 +50,7 @@ fn retrieve(id: PasteId) -> Option<File> {
}
#[post("/", data = "<paste>")]
fn upload(paste: Data) -> Result<String, std::io::Error> {
fn upload(paste: Data) -> Result<Redirect, std::io::Error> {
let id = PasteId::new(4);
let filename = format!("upload/{id}", id = id);
@@ -65,19 +65,17 @@ fn upload(paste: Data) -> Result<String, std::io::Error> {
.contains("text")
{
true => format!(
"https://{host}/p/{id}\n",
host = env::var("HOST_URL").unwrap_or("<no_host_provided>".to_string()),
"/p/{id}",
id = id
),
false => format!(
"https://{host}/{id}\n",
host = env::var("HOST_URL").unwrap_or("http://localhost:8000".to_string()),
"/{id}",
id = id
),
)
};
Ok(url)
Ok(Redirect::to(url))
}
#[derive(FromForm)]