mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* build: embed binary checksums in the npm package * Update docs/tutorial/installation.md Co-authored-by: Jeremy Rose <jeremya@chromium.org> * refactor: replace reduce with loop * refactor: remove all usages of the legacy request module (#30492) * Replaces request with got * Replaces nugget with got streams * Replaces request in docs with got * Upgrades dugite to drop requests dependency * build: do not excessively log response bodies * build: fix publish-to-npm script post requests migration * chore: revert accidental package bumps Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Samuel Attard <sam@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const { Octokit } = require('@octokit/rest');
|
|
const got = require('got');
|
|
|
|
const octokit = new Octokit({
|
|
userAgent: 'electron-asset-fetcher',
|
|
auth: process.env.ELECTRON_GITHUB_TOKEN
|
|
});
|
|
|
|
async function getAssetContents (repo, assetId) {
|
|
const requestOptions = octokit.repos.getReleaseAsset.endpoint({
|
|
owner: 'electron',
|
|
repo,
|
|
asset_id: assetId,
|
|
headers: {
|
|
Accept: 'application/octet-stream'
|
|
}
|
|
});
|
|
|
|
const { url, headers } = requestOptions;
|
|
headers.authorization = `token ${process.env.ELECTRON_GITHUB_TOKEN}`;
|
|
|
|
const response = await got(url, {
|
|
followRedirect: false,
|
|
method: 'HEAD',
|
|
headers
|
|
});
|
|
if (!response.headers.location) {
|
|
console.error(response.headers, `${response.body}`.slice(0, 300));
|
|
throw new Error(`cannot find asset[${assetId}], asset download did not redirect`);
|
|
}
|
|
|
|
const fileResponse = await got(response.headers.location);
|
|
if (fileResponse.statusCode !== 200) {
|
|
console.error(fileResponse.headers, `${fileResponse.body}`.slice(0, 300));
|
|
throw new Error(`cannot download asset[${assetId}] from ${response.headers.location}, got status: ${fileResponse.status}`);
|
|
}
|
|
|
|
return fileResponse.body;
|
|
}
|
|
|
|
module.exports = {
|
|
getAssetContents
|
|
};
|