-
Notifications
You must be signed in to change notification settings - Fork 43
/
pdfjs-get.js
36 lines (32 loc) · 1.13 KB
/
pdfjs-get.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
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
const path = require('path')
const AdmZip = require('adm-zip')
const axios = require('axios')
const cliProgress = require('cli-progress')
const npmPackage = require('./package.json')
// Fetching pdf.js build release
const PDFJSversion = npmPackage.dependencies['pdfjs-dist'].slice(1)
console.info('Fetching pdfjs', PDFJSversion)
// Init progress
const pdfjsProgress = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
pdfjsProgress.start(100, 0)
axios.get(`https://github.com/mozilla/pdf.js/releases/download/v${PDFJSversion}/pdfjs-${PDFJSversion}-dist.zip`, {
onDownloadProgress: ({loaded, total}) => {
pdfjsProgress.update(loaded / total * 100)
if (loaded === total) {
pdfjsProgress.update(100)
pdfjsProgress.stop()
console.info('Done! \n')
}
},
responseType: 'arraybuffer',
}).then(response => {
const zip = new AdmZip(response.data)
zip.extractAllTo(path.resolve(__dirname, 'js', 'pdfjs'))
}).catch(err => {
console.error(err)
throw new Error('Unable to download pdfjs dist')
})