chore: Prettified Code

[ci skip]
This commit is contained in:
maikirakiwi 2022-10-17 02:52:21 +00:00 committed by cider-chore[bot]
parent 4cb8cf5a19
commit 4a1cf5fed8
2 changed files with 14 additions and 7 deletions

View file

@ -921,9 +921,14 @@ export class BrowserWindow {
if (url.endsWith("/")) url = url.slice(0, -1); if (url.endsWith("/")) url = url.slice(0, -1);
let response = await utils.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 repo = url.split("/").slice(-2).join("/");
let apiRepo = await utils.fetch(`https://api.github.com/repos/${repo}`, { headers: { let apiRepo = await utils
"User-Agent": utils.getWindow().webContents.getUserAgent()}}).then((res) => res.json()); .fetch(`https://api.github.com/repos/${repo}`, {
console.error(apiRepo) headers: {
"User-Agent": utils.getWindow().webContents.getUserAgent(),
},
})
.then((res) => res.json());
console.error(apiRepo);
console.debug(`REPO ID: ${apiRepo.id}`); console.debug(`REPO ID: ${apiRepo.id}`);
// extract the files from the first folder in the zip response // extract the files from the first folder in the zip response
let zip = new AdmZip(await response.buffer()); let zip = new AdmZip(await response.buffer());
@ -940,7 +945,7 @@ export class BrowserWindow {
theme.commit = commit[0].sha; theme.commit = commit[0].sha;
writeFileSync(join(utils.getPath("themes"), "gh_" + apiRepo.id, "theme.json"), JSON.stringify(theme, null, 4), "utf8"); writeFileSync(join(utils.getPath("themes"), "gh_" + apiRepo.id, "theme.json"), JSON.stringify(theme, null, 4), "utf8");
} catch (e) { } catch (e) {
console.error(e) console.error(e);
returnVal.success = false; returnVal.success = false;
} }
BrowserWindow.win.webContents.send("theme-installed", returnVal); BrowserWindow.win.webContents.send("theme-installed", returnVal);

View file

@ -85,9 +85,11 @@ export class utils {
* @param opts {object} Other options * @param opts {object} Other options
*/ */
static async fetch(url: string, opts = {}) { static async fetch(url: string, opts = {}) {
Object.assign(opts, { headers: { Object.assign(opts, {
"User-Agent": utils.getWindow().webContents.getUserAgent()} headers: {
}) "User-Agent": utils.getWindow().webContents.getUserAgent(),
},
});
if (this.getStoreValue("advanced.experiments").includes("cider_mirror") === true) { if (this.getStoreValue("advanced.experiments").includes("cider_mirror") === true) {
if (url.includes("api.github.com/")) { if (url.includes("api.github.com/")) {
return await 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);