templates, main: copy and paste images

Make use of the Clipboard API. Also vivi dis is for you

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain
2021-07-08 19:48:05 +05:30
parent 0cd0d24549
commit 7726a0e0ee
2 changed files with 23 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use rocket::data::{Data, ToByteUnit}; use rocket::data::{Data, ToByteUnit};
use rocket::shield::{Shield, NoSniff};
use rocket::{form::Form, response::Redirect}; use rocket::{form::Form, response::Redirect};
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
@@ -117,6 +118,8 @@ async fn index() -> Option<Template> {
#[launch] #[launch]
fn rocket() -> _ { fn rocket() -> _ {
let shield = Shield::default().disable::<NoSniff>();
rocket::build() rocket::build()
.mount( .mount(
"/", "/",
@@ -129,5 +132,6 @@ fn rocket() -> _ {
pretty_retrieve_ext pretty_retrieve_ext
], ],
) )
.attach(shield)
.attach(Template::fairing()) .attach(Template::fairing())
} }

View File

@@ -119,15 +119,12 @@ AUTHOR
} }
function dropHandler(ev) { function dropHandler(ev) {
console.log('File(s) dropped');
ev.preventDefault(); ev.preventDefault();
if (ev.dataTransfer.items) { if (ev.dataTransfer.items) {
for (var i = 0; i < ev.dataTransfer.items.length; i++) { for (var i = 0; i < ev.dataTransfer.items.length; i++) {
if (ev.dataTransfer.items[i].kind === 'file') { if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile(); var file = ev.dataTransfer.items[i].getAsFile();
console.log('... file[' + i + '].name = ' + file.name);
var url = window.location.href; var url = window.location.href;
@@ -140,18 +137,29 @@ AUTHOR
}); });
} }
} }
} else { }
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
}
}
} }
function dragOverHandler(ev) { function dragOverHandler(ev) {
console.log('File(s) in drop zone');
ev.preventDefault(); ev.preventDefault();
} }
document.onpaste = function(pasteEvent) {
var item = pasteEvent.clipboardData.items[0];
var blob = item.getAsFile();
if (blob !== null && blob !== '') {
var url = window.location.href;
postData(url, blob)
.then(data => {
window.location.href = data.url;
})
.catch(function (err) {
console.info(err + " url: " + url);
});
}
}
</script> </script>
{% endblock body %} {% endblock body %}