dropzone.js handle upload of document for a better UX

This commit is contained in:
2018-09-13 21:01:47 +02:00
parent 823aee2264
commit e55d654675
9 changed files with 275 additions and 104 deletions

View File

@@ -29,6 +29,8 @@ var download = (button) => {
labelReady = button.dataset.labelReady,
mimeType = button.dataset.mimeType,
extension = mime.extension(mimeType),
decryptError = "Error while decrypting file",
fetchError = "Error while fetching file",
key, url
;
@@ -44,14 +46,25 @@ var download = (button) => {
})
.then(data => {
url = data.url;
return window.crypto.subtle.importKey('jwk', keyData, { name: algo, iv: iv}, false, ['decrypt']);
})
.catch(e => {
console.error("error while importing key");
console.error(e);
button.appendChild(document.createTextNode(decryptError));
})
.then(nKey => {
key = nKey;
return window.fetch(url);
})
.catch(e => {
console.error("error while fetching data");
console.error(e);
button.textContent = "";
button.appendChild(document.createTextNode(fetchError));
})
.then(r => {
if (r.ok) {
return r.arrayBuffer();
@@ -62,6 +75,12 @@ var download = (button) => {
.then(buffer => {
return window.crypto.subtle.decrypt({ name: algo, iv: iv }, key, buffer);
})
.catch(e => {
console.error("error while importing key");
console.error(e);
button.textContent = "";
button.appendChild(document.createTextNode(decryptError));
})
.then(decrypted => {
var
blob = new Blob([decrypted], { type: mimeType }),
@@ -82,6 +101,8 @@ var download = (button) => {
})
.catch(error => {
console.log(error);
button.textContent = "";
button.appendChild(document.createTextNode("error while handling decrypted file"));
})
;
};
@@ -89,3 +110,5 @@ var download = (button) => {
window.addEventListener('load', function(e) {
initializeButtons(e.target);
});
module.exports = initializeButtons;