-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
45 lines (41 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// This is all of the Penumbra-relevant code:
const onReady = async (
{ detail: { penumbra } } = {
detail: self,
},
) => {
// Download and decrypt and display in table
// TODO: fix demo table cell association
penumbra
.get(...window.files)
.then((pfiles) => penumbra.getTextOrURI(pfiles))
// .then(insertIntoCell);
.then(window.insertIntoCell);
const runOnce = {};
// Display download progress
window.addEventListener(
'penumbra-progress',
({ detail: { percent, id, contentLength } }) => {
const i = window.files.findIndex(
(elt) => 'url' in elt && typeof id !== 'undefined' && elt.url === id,
);
if (i !== -1) {
const cell = document.getElementById(`${i}-progress`);
cell.innerText = `${percent}%`;
if (!runOnce[i]) {
const cell2 = document.getElementById(`${i}-size`);
cell2.innerText = `${contentLength / 1000}KB`;
runOnce[i] = true;
}
}
},
);
// Function to download and zip
// const downloadManyFiles = () =>
// penumbra.get(...window.files).then((pfiles) => penumbra.save(pfiles));
};
if (!self.penumbra) {
self.addEventListener('penumbra-ready', onReady);
} else {
onReady();
}