diff --git a/app/common/adapter/binary/AbstractBinary.ts b/app/common/adapter/binary/AbstractBinary.ts index f811f80f..82d8e4c2 100644 --- a/app/common/adapter/binary/AbstractBinary.ts +++ b/app/common/adapter/binary/AbstractBinary.ts @@ -45,12 +45,13 @@ export abstract class AbstractBinary { return xml; } - protected async requestJSON(url: string) { + protected async requestJSON(url: string, requestHeaders?: Record) { const { status, data, headers } = await this.httpclient.request(url, { timeout: 30000, dataType: 'json', followRedirect: true, gzip: true, + headers: requestHeaders, }); if (status !== 200) { this.logger.warn('[AbstractBinary.requestJSON:non-200-status] url: %s, status: %s, headers: %j', url, status, headers); diff --git a/app/common/adapter/binary/GithubBinary.ts b/app/common/adapter/binary/GithubBinary.ts index bfae2f84..b2d311ff 100644 --- a/app/common/adapter/binary/GithubBinary.ts +++ b/app/common/adapter/binary/GithubBinary.ts @@ -21,7 +21,11 @@ export class GithubBinary extends AbstractBinary { const maxPage = binaryConfig.options?.maxPage || 1; for (let i = 0; i < maxPage; i++) { const url = `https://api.github.com/repos/${binaryConfig.repo}/releases?per_page=100&page=${i + 1}`; - const data = await this.requestJSON(url); + const requestHeaders: Record = {}; + if (process.env.GITHUB_TOKEN) { + requestHeaders.Authorization = `token ${process.env.GITHUB_TOKEN}`; + } + const data = await this.requestJSON(url, requestHeaders); if (!Array.isArray(data)) { // {"message":"API rate limit exceeded for 47.57.239.54. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"} if (typeof data?.message === 'string' && data.message.includes('rate limit')) {