generate document with relatorio: config and driver

This commit is contained in:
2021-12-02 17:00:09 +01:00
parent 475b40e896
commit 2245f83631
7 changed files with 177 additions and 74 deletions

View File

@@ -5,7 +5,7 @@ var algo = 'AES-CBC';
var initializeButtons = (root) => {
var
buttons = root.querySelectorAll('a[data-download-button]');
for (let i = 0; i < buttons.length; i ++) {
initialize(buttons[i]);
}
@@ -33,9 +33,12 @@ var download = (button) => {
fetchError = "Error while fetching file",
key, url
;
console.log('keyData', keyData);
console.log('ivData', ivData);
button.textContent = labelPreparing;
window.fetch(urlGenerator)
.then((r) => {
if (r.ok) {
@@ -46,26 +49,19 @@ 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));
if (keyData.length > 0) {
return window.crypto.subtle.importKey('jwk', keyData, { name: algo, iv: iv}, false, ['decrypt']);
}
return Promise.resolve(undefined);
})
.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 => {
console.log('r', r);
if (r.ok) {
return r.arrayBuffer();
} else {
@@ -73,16 +69,16 @@ 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));
console.log('buffer', buffer);
if (keyData.length > 0) {
return window.crypto.subtle.decrypt({ name: algo, iv: iv }, key, buffer);
}
return Promise.resolve(buffer);
})
.then(decrypted => {
var
console.log('decrypted', decrypted);
var
blob = new Blob([decrypted], { type: mimeType }),
url = window.URL.createObjectURL(blob)
;