Skip to content

Commit

Permalink
use browser_download_url
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Jun 18, 2024
1 parent 28eb436 commit 2e1bde2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 6 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35831,14 +35831,16 @@ async function downloadCage({ version, token, }) {
throw new Error(`Checksums not found for ${version}`);
if (!asset)
throw new Error(`Asset not found for ${platformArch}`);
console.assert(asset.url.startsWith("https://"), "asset.url is not secure: %s", asset.url);
console.assert(checksums.url.startsWith("https://"), "checksums.url is not secure: %s", checksums.url);
const checksumsContent = await tc.downloadTool(checksums.url);
const assetUrl = asset.browser_download_url;
const checksumsUrl = checksums.browser_download_url;
console.assert(assetUrl.startsWith("https://"), "asset.url is not secure: %s", assetUrl);
console.assert(checksumsUrl.startsWith("https://"), "checksumsUrl is not secure: %s", checksumsUrl);
const checksumsContent = await tc.downloadTool(checksumsUrl);
const checksumEntries = await parseChecksum(checksumsContent);
const hash = checksumEntries.get(asset.name);
if (!hash)
throw new Error(`Checksum not found for ${asset.name}`);
const zip = await tc.downloadTool(asset.url);
const zip = await tc.downloadTool(assetUrl);
const zipFile = await promises_1.default.open(zip, "r");
const zipHash = await sha256hashAsync(zipFile.createReadStream());
if (zipHash !== hash) {
Expand Down
2 changes: 1 addition & 1 deletion src/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("downloadCage", () => {
beforeEach(() => {
const makeAsset = (version: string, name: string) => ({
name,
url: `https://github.com/loilo-inc/canarycage/releases/download/${version}/${name}`,
browser_download_url: `https://github.com/loilo-inc/canarycage/releases/download/${version}/${name}`,
});
const makeRelease = (tag_name: string) => ({
tag_name,
Expand Down
16 changes: 9 additions & 7 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ export async function downloadCage({
);
if (!checksums) throw new Error(`Checksums not found for ${version}`);
if (!asset) throw new Error(`Asset not found for ${platformArch}`);
const assetUrl = asset.browser_download_url;
const checksumsUrl = checksums.browser_download_url;
console.assert(
asset.url.startsWith("https://"),
assetUrl.startsWith("https://"),
"asset.url is not secure: %s",
asset.url,
assetUrl,
);
console.assert(
checksums.url.startsWith("https://"),
"checksums.url is not secure: %s",
checksums.url,
checksumsUrl.startsWith("https://"),
"checksumsUrl is not secure: %s",
checksumsUrl,
);
const checksumsContent = await tc.downloadTool(checksums.url);
const checksumsContent = await tc.downloadTool(checksumsUrl);
const checksumEntries = await parseChecksum(checksumsContent);
const hash = checksumEntries.get(asset.name);
if (!hash) throw new Error(`Checksum not found for ${asset.name}`);
const zip = await tc.downloadTool(asset.url);
const zip = await tc.downloadTool(assetUrl);
const zipFile = await fs.open(zip, "r");
const zipHash = await sha256hashAsync(zipFile.createReadStream());
if (zipHash !== hash) {
Expand Down

0 comments on commit 2e1bde2

Please sign in to comment.