Use fetchJson instead of checkedFetch

This commit is contained in:
Nuckyz 2025-05-28 10:35:59 -03:00
parent 8c085dd932
commit ebb2da1366
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { checkedFetch, fetchBuffer } from "@main/utils/http"; import { fetchBuffer, fetchJson } from "@main/utils/http";
import { IpcEvents } from "@shared/IpcEvents"; import { IpcEvents } from "@shared/IpcEvents";
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
import { ipcMain } from "electron"; import { ipcMain } from "electron";
@ -31,8 +31,8 @@ import { serializeErrors, VENCORD_FILES } from "./common";
const API_BASE = `https://api.github.com/repos/${gitRemote}`; const API_BASE = `https://api.github.com/repos/${gitRemote}`;
let PendingUpdates = [] as [string, string][]; let PendingUpdates = [] as [string, string][];
async function githubGet(endpoint: string) { async function githubGet<T = any>(endpoint: string) {
return checkedFetch(API_BASE + endpoint, { return fetchJson<T>(API_BASE + endpoint, {
headers: { headers: {
Accept: "application/vnd.github+json", Accept: "application/vnd.github+json",
// "All API requests MUST include a valid User-Agent header. // "All API requests MUST include a valid User-Agent header.
@ -46,7 +46,7 @@ async function calculateGitChanges() {
const isOutdated = await fetchUpdates(); const isOutdated = await fetchUpdates();
if (!isOutdated) return []; if (!isOutdated) return [];
const data = await githubGet(`/compare/${gitHash}...HEAD`).then(res => res.json()); const data = await githubGet(`/compare/${gitHash}...HEAD`);
return data.commits.map((c: any) => ({ return data.commits.map((c: any) => ({
// github api only sends the long sha // github api only sends the long sha
@ -57,7 +57,7 @@ async function calculateGitChanges() {
} }
async function fetchUpdates() { async function fetchUpdates() {
const data = await githubGet("/releases/latest").then(res => res.json()); const data = await githubGet("/releases/latest");
const hash = data.name.slice(data.name.lastIndexOf(" ") + 1); const hash = data.name.slice(data.name.lastIndexOf(" ") + 1);
if (hash === gitHash) if (hash === gitHash)