From 76f6364f6ddab8c63ea24789239b56ad0d793954 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 30 Oct 2023 01:23:34 +0800 Subject: [PATCH] fix: add User-Agent header to bypass API check --- api/[owner]/[app]/[version].ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/[owner]/[app]/[version].ts b/api/[owner]/[app]/[version].ts index 7b5b15c3..558d2742 100644 --- a/api/[owner]/[app]/[version].ts +++ b/api/[owner]/[app]/[version].ts @@ -10,6 +10,13 @@ export interface DownloadInfo { const NOT_FOUND = 404 +const FETCH_OPTIONS = { + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', + }, +} + export const config = { runtime: 'edge', } @@ -32,7 +39,7 @@ export default async (req: Request): Promise => { console.log(`Fetching ${releasesUrl}`) - const releasesRes = await fetch(releasesUrl) + const releasesRes = await fetch(releasesUrl, FETCH_OPTIONS) const releases = (await releasesRes.json()) as ReleaseInfo[] const matched = releases.find( @@ -52,7 +59,7 @@ export default async (req: Request): Promise => { console.log(`Fetching ${releaseUrl}`) - const downloadInfoRes = await fetch(releaseUrl) + const downloadInfoRes = await fetch(releaseUrl, FETCH_OPTIONS) const { download_url: downloadUrl } = (await downloadInfoRes.json()) as DownloadInfo