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:
@@ -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())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 %}
|
||||||
|
|||||||
Reference in New Issue
Block a user