mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-12-19 00:25:42 +00:00
dropzone.js handle upload of document for a better UX
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user