From 9ad8773b4da71f69cb11173ba3d235f04e7e46ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Wed, 8 Jan 2025 13:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Mirror=20source=20improvement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/github.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/electron/api/github.ts b/electron/api/github.ts index b19c9d5..6f00346 100644 --- a/electron/api/github.ts +++ b/electron/api/github.ts @@ -241,9 +241,15 @@ export const initGitHubApi = () => { const conventMirrorUrl = (mirror: string) => { switch (mirror) { case "github": - return "https://api.github.com"; + return { + api: "https://api.github.com", + asset: "https://github.com" + }; default: - return "https://api.github.com"; + return { + api: "https://api.github.com", + asset: "https://github.com" + }; } }; @@ -251,7 +257,8 @@ export const initGitHubApi = () => { * 获取github上的frp所有版本 */ ipcMain.on("github.getFrpVersions", async (event, mirror: string) => { - const mirrorUrl = conventMirrorUrl(mirror); + const { api } = conventMirrorUrl(mirror); + const mirrorUrl = api; log.info("Requesting mirror URL: ", mirrorUrl); const request = net.request({ method: "get", @@ -307,10 +314,14 @@ export const initGitHubApi = () => { const asset = getAdaptiveAsset(versionId); const { browser_download_url } = asset; - let url = browser_download_url; - if (mirror === "ghproxy") { - url = "https://mirror.ghproxy.com/" + url; - } + let url = browser_download_url.replace( + "https://github.com", + conventMirrorUrl(mirror).asset + ); + + // if (mirror === "ghproxy") { + // url = "https://mirror.ghproxy.com/" + url; + // } logDebug( LogModule.GITHUB, @@ -328,7 +339,9 @@ export const initGitHubApi = () => { }); logDebug( LogModule.GITHUB, - `Download progress for versionId: ${versionId} is ${progress}%` + `Download progress for versionId: ${versionId} is ${ + progress.percent * 100 + }%` ); }, onCompleted: () => {