diff --git a/src/main.rs b/src/main.rs index 041b2a7..a56916d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ fn rocket() -> _ { routes::upload::upload, routes::submit::submit, routes::retrieve::retrieve, + routes::retrieve::retrieve_ext, routes::pretty_retrieve::pretty_retrieve, routes::pretty_retrieve_ext::pretty_retrieve_ext ], diff --git a/src/routes/retrieve.rs b/src/routes/retrieve.rs index 1465228..de11558 100644 --- a/src/routes/retrieve.rs +++ b/src/routes/retrieve.rs @@ -1,10 +1,20 @@ use std::fs::File; +use crate::models::pretty_syntax::PasteIdSyntax; use crate::models::paste_id::PasteId; -#[get("/")] +#[get("/", rank = 2)] pub async fn retrieve(id: PasteId<'_>) -> Option { let filename = format!("upload/{id}", id = id); File::open(&filename).ok() -} \ No newline at end of file +} + +// rank 1 here because this would be more oftenly used +#[get("/", rank = 1)] +pub async fn retrieve_ext(id_ext: PasteIdSyntax<'_>) -> Option { + let filename = format!("upload/{id}", id = id_ext.get_fname()); + + File::open(&filename).ok() +} + diff --git a/templates/index.html.tera b/templates/index.html.tera index 1056da7..268a46b 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -126,32 +126,31 @@ AUTHOR return response; } + // drag and drop files function dropHandler(ev) { ev.preventDefault(); if (ev.dataTransfer.items) { - for (var i = 0; i < ev.dataTransfer.items.length; i++) { - if (ev.dataTransfer.items[i].kind === 'file') { - var file = ev.dataTransfer.items[i].getAsFile(); + var item = ev.dataTransfer.items[0]; + var blob = item.getAsFile(); + const ext = blob.name.split(".")[1]; + var url = window.location.href; - var url = window.location.href; - - postData(url, file) - .then(data => { - window.location.href = data.url; - }) - .catch(function (err) { - console.info(err + " url: " + url); - }); - } - } - } + postData(url, blob) + .then(data => { + window.location.href = data.url + "." + ext; + }) + .catch(function (err) { + console.info(err + " url: " + url); + }); + } } function dragOverHandler(ev) { ev.preventDefault(); } + // pasting files from the clipboard document.onpaste = function(pasteEvent) { var item = pasteEvent.clipboardData.items[0]; var blob = item.getAsFile();