From 2bf7d3990fa50a83366fa64558e6e15023d361b5 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 20 Nov 2024 09:56:24 -0800 Subject: [PATCH] fix: release download urls without ratelimiting --- npm/weval/index.js | 49 +++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/npm/weval/index.js b/npm/weval/index.js index 9a23eba..66c1982 100644 --- a/npm/weval/index.js +++ b/npm/weval/index.js @@ -60,36 +60,27 @@ async function getWeval() { } await mkdir(exeDir, { recursive: true }); - let repoBaseURL = `https://api.github.com/repos/bytecodealliance/weval`; - let response = await getJSON(`${repoBaseURL}/releases/tags/${TAG}`); - let id = response.id; - let assets = await getJSON(`${repoBaseURL}/releases/${id}/assets`); - let releaseAsset = `weval-${TAG}-${platformName}.${assetSuffix}`; - let asset = assets.find(asset => asset.name === releaseAsset); - if (!asset) { - console.error(`Can't find an asset named ${releaseAsset}`); - process.exit(1); - } - let data = await fetch(asset.browser_download_url); - if (!data.ok) { - console.error(`Error downloading ${asset.browser_download_url}`); - process.exit(1); - } - let buf = await data.arrayBuffer(); + const downloadUrl = `https://github.com/bytecodealliance/weval/releases/download/${TAG}/weval-${TAG}-${platformName}.${assetSuffix}`; + let data = await fetch(downloadUrl); + if (!data.ok) { + console.error(`Error downloading ${downloadUrl}`); + process.exit(1); + } + let buf = await data.arrayBuffer(); - if (releaseAsset.endsWith('.xz')) { - buf = await xz.decompress(new Uint8Array(buf)); - } - await decompress(Buffer.from(buf), exeDir, { - // Remove the leading directory from the extracted file. - strip: 1, - plugins: [ - decompressUnzip(), - decompressTar() - ], - // Only extract the binary file and nothing else - filter: file => parse(file.path).base === `weval${exeSuffix}`, - }); + if (downloadUrl.endsWith('.xz')) { + buf = await xz.decompress(new Uint8Array(buf)); + } + await decompress(Buffer.from(buf), exeDir, { + // Remove the leading directory from the extracted file. + strip: 1, + plugins: [ + decompressUnzip(), + decompressTar() + ], + // Only extract the binary file and nothing else + filter: file => parse(file.path).base === `weval${exeSuffix}`, + }); return exe; }