From 4cb8cf5a19d32b7c70404c36a90be8d253ff1760 Mon Sep 17 00:00:00 2001 From: Maikiwi Date: Sun, 16 Oct 2022 19:51:48 -0700 Subject: [PATCH] weird stuff --- src/main/base/browserwindow.ts | 7 +++++-- src/main/base/utils.ts | 13 ++++++++----- src/renderer/main/vueapp.js | 24 +++++++++++++----------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 07037670..66c5e2b0 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -770,7 +770,7 @@ export class BrowserWindow { }; Object.assign(options, args); - let res = await utils.fetch( + let res = await fetch( `https://amp-api.music.apple.com/${options.route}?${new URLSearchParams({ ...options.GETBody, }).toString()}`, @@ -921,7 +921,9 @@ export class BrowserWindow { if (url.endsWith("/")) url = url.slice(0, -1); let response = await utils.fetch(`${url}/archive/refs/heads/main.zip`); let repo = url.split("/").slice(-2).join("/"); - let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()); + let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`, { headers: { + "User-Agent": utils.getWindow().webContents.getUserAgent()}}).then((res) => res.json()); + console.error(apiRepo) console.debug(`REPO ID: ${apiRepo.id}`); // extract the files from the first folder in the zip response let zip = new AdmZip(await response.buffer()); @@ -938,6 +940,7 @@ export class BrowserWindow { theme.commit = commit[0].sha; writeFileSync(join(utils.getPath("themes"), "gh_" + apiRepo.id, "theme.json"), JSON.stringify(theme, null, 4), "utf8"); } catch (e) { + console.error(e) returnVal.success = false; } BrowserWindow.win.webContents.send("theme-installed", returnVal); diff --git a/src/main/base/utils.ts b/src/main/base/utils.ts index 85a72906..332c0d7e 100644 --- a/src/main/base/utils.ts +++ b/src/main/base/utils.ts @@ -84,17 +84,20 @@ export class utils { * @param url {string} URL param * @param opts {object} Other options */ - static fetch(url: string, opts = {}) { + static async fetch(url: string, opts = {}) { + Object.assign(opts, { headers: { + "User-Agent": utils.getWindow().webContents.getUserAgent()} + }) if (this.getStoreValue("advanced.experiments").includes("cider_mirror") === true) { if (url.includes("api.github.com/")) { - return fetch(url.replace("api.github.com/", "mirror.api.cider.sh/v2/api/"), opts); + return await fetch(url.replace("api.github.com/", "mirror.api.cider.sh/v2/api/"), opts); } else if (url.includes("raw.githubusercontent.com/")) { - return fetch(url.replace("raw.githubusercontent.com/", "mirror.api.cider.sh/v2/raw/"), opts); + return await fetch(url.replace("raw.githubusercontent.com/", "mirror.api.cider.sh/v2/raw/"), opts); } else { - return fetch(url, opts); + return await fetch(url, opts); } } else { - return fetch(url, opts); + return await fetch(url, opts); } } /** diff --git a/src/renderer/main/vueapp.js b/src/renderer/main/vueapp.js index 2b3b5f9f..a2bf4327 100644 --- a/src/renderer/main/vueapp.js +++ b/src/renderer/main/vueapp.js @@ -1303,17 +1303,19 @@ const app = new Vue({ const themes = ipcRenderer.sendSync("get-themes"); await asyncForEach(themes, async (theme) => { if (theme.commit != "") { - await app._fetch(`https://api.github.com/repos/${theme.github_repo}/commits`).then((res) => res.json()); - if (res[0].sha != theme.commit) { - const notify = notyf.open({ - className: "notyf-info", - type: "info", - message: app.stringTemplateParser(app.getLz("settings.notyf.visual.theme.updateAvailable"), { theme: theme.name }), - }); - notify.on("click", () => { - app.openSettingsPage("github-themes"); - notyf.dismiss(notify); - }); + if (theme.commit != "") { + app._fetch(`https://api.github.com/repos/${theme.github_repo}/commits`).then((res) => res.json()); + if (res[0].sha != theme.commit) { + const notify = notyf.open({ + className: "notyf-info", + type: "info", + message: app.stringTemplateParser(app.getLz("settings.notyf.visual.theme.updateAvailable"), { theme: theme.name }), + }); + notify.on("click", () => { + app.openSettingsPage("github-themes"); + notyf.dismiss(notify); + }); + } } } });