This maybe works
This commit is contained in:
parent
4b2513330c
commit
51f28144d0
4 changed files with 36 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue