weird stuff

This commit is contained in:
Maikiwi 2022-10-16 19:51:48 -07:00
parent 6a67cd8a54
commit 4cb8cf5a19
3 changed files with 26 additions and 18 deletions

View file

@ -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);

View file

@ -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);
}
}
/**

View file

@ -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);
});
}
}
}
});