From 0126cfed1d98813e003c08b71c6083ec0b7d724e Mon Sep 17 00:00:00 2001 From: "Orhan \"aib\" Kavrakoglu" Date: Thu, 27 Jun 2024 20:00:55 +0300 Subject: [PATCH] Attempt public download before using the token and API --- bin.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bin.js b/bin.js index e5260cc..53f8570 100755 --- a/bin.js +++ b/bin.js @@ -54,25 +54,28 @@ if (opts.force) { process.exit(1) } -const startDownload = function (downloadUrl) { - download(downloadUrl, opts, function (err) { - if (err) { - log.warn('install', err.message) - return process.exit(1) - } - log.info('install', 'Successfully installed prebuilt binary!') - }) -} +download(util.getDownloadUrl(opts), opts, function (err) { + if (err) { + if (opts.token) { + log.info('install', 'public download failed, retrying using token') + asset(opts, function (err, assetId) { + if (err) { + log.warn('install', err.message) + return process.exit(1) + } -if (opts.token) { - asset(opts, function (err, assetId) { - if (err) { + download(util.getAssetUrl(opts, assetId), opts, function (err) { + if (err) { + log.warn('install', err.message) + return process.exit(1) + } + log.info('install', 'Successfully installed prebuilt binary!') + }) + }) + } else { log.warn('install', err.message) return process.exit(1) } - - startDownload(util.getAssetUrl(opts, assetId)) - }) -} else { - startDownload(util.getDownloadUrl(opts)) -} + } + log.info('install', 'Successfully installed prebuilt binary!') +})