-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.js
55 lines (41 loc) · 1.26 KB
/
template.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
46
47
48
49
50
51
52
53
54
55
// ****
(async () => {
// ****
// ********************************************************
// JSZip
/* {LIB_JSZIP} */
// ********************************************************
// ********************************************************
// FileSaver
/* {LIB_FILESAVER} */
// ********************************************************
/* {FILE_SUFFIX} */
/* {URL_LIST} */
/* {MODIFY_NAME} */
const zip = new JSZip();
for (let i = 0; i < urls.length; i++) {
console.log(`Fetching ${i + 1}/${urls.length}`);
const url = urls[i];
const prefix = ((i + 1) + '').padStart(Math.ceil(Math.log10(urls.length)), '0');
const name = typeof MODIFY_NAME === 'function'
? MODIFY_NAME(url, i, urls.length)
: `${prefix}${typeof FILE_SUFFIX === 'string' ? FILE_SUFFIX : ''}`;
try {
const request = fetch(url);
const data = new Uint8Array((await (await request).arrayBuffer()));
zip.file(name, data);
// Delay
await new Promise(r => setTimeout(r, /* {REQUEST_INTERVAL} */));
} catch (e) {
console.log(`Error fetching ${i + 1}/${urls.length} ${url}`);
}
}
console.log('Generating zip...')
zip.generateAsync({ type: 'blob' })
.then(blob => {
console.log('Downloading...')
saveAs(blob, "/* {ZIP_FILENAME} */")
});
// ****
})();
// ****