From 51f28144d0302a37b957f8370c880e81362591bb Mon Sep 17 00:00:00 2001 From: Maikiwi Date: Sun, 16 Oct 2022 17:26:52 -0700 Subject: [PATCH] This maybe works --- src/main/base/browserwindow.ts | 14 +++++------ src/main/base/utils.ts | 24 +++++++++++++++++++ .../views/components/settings-window.ejs | 8 +++---- src/renderer/views/main.ejs | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index f0b4731a..07037670 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 fetch( + let res = await utils.fetch( `https://amp-api.music.apple.com/${options.route}?${new URLSearchParams({ ...options.GETBody, }).toString()}`, @@ -882,9 +882,9 @@ export class BrowserWindow { mkdirSync(utils.getPath("plugins")); } if (url.endsWith("/")) url = url.slice(0, -1); - let response = await fetch(`${url}/archive/refs/heads/main.zip`); + let response = await utils.fetch(`${url}/archive/refs/heads/main.zip`); let repo = url.split("/").slice(-2).join("/"); - let apiRepo = await fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()); + let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()); console.debug(`REPO ID: ${apiRepo.id}`); // extract the files from the first folder in the zip response let zip = new AdmZip(await response.buffer()); @@ -894,7 +894,7 @@ export class BrowserWindow { } console.log(join(utils.getPath("plugins"), "gh_" + apiRepo.id)); zip.extractEntryTo(entry, join(utils.getPath("plugins"), "gh_" + apiRepo.id), false, true); - let commit = await fetch(`https://api.github.com/repos/${repo}/commits`).then((res) => res.json()); + let commit = await utils.fetch(`https://api.github.com/repos/${repo}/commits`).then((res) => res.json()); console.debug(`COMMIT SHA: ${commit[0].sha}`); let theme = JSON.parse(readFileSync(join(utils.getPath("plugins"), "gh_" + apiRepo.id, "package.json"), "utf8")); theme.id = apiRepo.id; @@ -919,9 +919,9 @@ export class BrowserWindow { mkdirSync(utils.getPath("themes")); } if (url.endsWith("/")) url = url.slice(0, -1); - let response = await fetch(`${url}/archive/refs/heads/main.zip`); + let response = await utils.fetch(`${url}/archive/refs/heads/main.zip`); let repo = url.split("/").slice(-2).join("/"); - let apiRepo = await fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()); + let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`).then((res) => res.json()); console.debug(`REPO ID: ${apiRepo.id}`); // extract the files from the first folder in the zip response let zip = new AdmZip(await response.buffer()); @@ -931,7 +931,7 @@ export class BrowserWindow { } console.log(join(utils.getPath("themes"), "gh_" + apiRepo.id)); zip.extractEntryTo(entry, join(utils.getPath("themes"), "gh_" + apiRepo.id), false, true); - let commit = await fetch(`https://api.github.com/repos/${repo}/commits`).then((res) => res.json()); + let commit = await utils.fetch(`https://api.github.com/repos/${repo}/commits`).then((res) => res.json()); console.debug(`COMMIT SHA: ${commit[0].sha}`); let theme = JSON.parse(readFileSync(join(utils.getPath("themes"), "gh_" + apiRepo.id, "theme.json"), "utf8")); theme.id = apiRepo.id; diff --git a/src/main/base/utils.ts b/src/main/base/utils.ts index fa408519..7773cfb7 100644 --- a/src/main/base/utils.ts +++ b/src/main/base/utils.ts @@ -3,6 +3,7 @@ import * as path from "path"; import { Store } from "./store"; import { BrowserWindow as bw } from "./browserwindow"; import { app, BrowserWindow, ipcMain } from "electron"; +import fetch from "electron-fetch"; import ElectronStore from "electron-store"; export class utils { @@ -77,6 +78,29 @@ export class utils { return bw.express; } + /** + * MitM the electron fetch for a function that proxies github. + * Written in TS so Maikiwi doesn't fuck up + * @param url {string} URL param + * @param opts {object} Other options + */ + static readonly _mirror: boolean = this.getStoreValue("advanced.experiments").includes('cider_mirror') ? true : false; + static fetch(url: string, opts = {}) { + if (this._mirror === true) { + if (url.includes("api.github.com/")) { + return 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); + } + else { + return fetch(url, opts); + } + } + else { + return fetch(url, opts); + } + } /** * Fetches the i18n locale for the given language. * @param language {string} The language to fetch the locale for. diff --git a/src/renderer/views/components/settings-window.ejs b/src/renderer/views/components/settings-window.ejs index 025ffaa7..96f63827 100644 --- a/src/renderer/views/components/settings-window.ejs +++ b/src/renderer/views/components/settings-window.ejs @@ -1241,14 +1241,14 @@
- Load MusicKit from Apple - Requires relaunch + Theme & Plugin Mirror to Cider + Only works in region where GitHub is blacklisted. Requires relaunch.
diff --git a/src/renderer/views/main.ejs b/src/renderer/views/main.ejs index 5d336dfa..703ca1fc 100644 --- a/src/renderer/views/main.ejs +++ b/src/renderer/views/main.ejs @@ -122,7 +122,7 @@ <% } %>