Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function downloadBinary() {
// TODO zip the binaries to reduce the download size
const downloadURL = getDownloadURL()
const extension = iswin ? ".exe" : ""
const fileName = `lefthook${extension}`
const binDir = path.join(__dirname, "bin")
const dl = new DownloaderHelper(downloadURL, binDir, {
fileName,
retry: { maxRetries: 5, delay: 50 },
})
dl.on("end", () => console.log("lefthook binary was downloaded"))
try {
await dl.start()
} catch(e) {
const message = `Failed to download ${fileName}: ${e.message} while fetching ${downloadURL}`
console.error(message)
throw new Error(message)
}
return path.join(binDir, fileName)
}
return await new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('Timeout')), (isPhoto) ? 10000 : 60000)
const dl = new DownloaderHelper(fileURL, path.resolve(savePath), {
override: true,
fileName: filename
})
dl.on('error', async (error) => {
await dl.stop()
logger.warn(`[Track: ${trackInfo.title}][${msg}]`, error)
reject(error)
}).on('timeout', async () => {
await dl.stop()
}).on('end', () => {
logger.debug(`[Track: ${trackInfo.title}][${msg}] Download completed!`)
resolve()
})
dl.start()