From 0ecc46ab97d3011f8dbfb8d00929b9a3190fae66 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Fri, 19 Apr 2024 17:35:49 -0400 Subject: [PATCH] Exclude authorization header where unnecessary --- src/account.ts | 2 +- src/system/game-data.ts | 8 ++++---- src/utils.ts | 12 ++++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/account.ts b/src/account.ts index a2ff71a6ed3..afb9aca3593 100644 --- a/src/account.ts +++ b/src/account.ts @@ -21,7 +21,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> { loggedInUser = { username: 'Guest', lastSessionSlot: lastSessionSlot }; return resolve([ true, 200 ]); } - Utils.apiFetch('account/info').then(response => { + Utils.apiFetch('account/info', true).then(response => { if (!response.ok) { resolve([ false, response.status ]); return; diff --git a/src/system/game-data.ts b/src/system/game-data.ts index e1ed38d8971..1c4dbaed2d1 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -407,7 +407,7 @@ export class GameData { } if (!bypassLogin) { - Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`) + Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`, true) .then(response => response.text()) .then(response => { if (!response.length || response[0] !== '{') { @@ -578,7 +578,7 @@ export class GameData { }; if (!bypassLogin) { - Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`) + Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`, true) .then(response => response.text()) .then(async response => { if (!response.length || response[0] !== '{') { @@ -707,7 +707,7 @@ export class GameData { updateUserInfo().then(success => { if (success !== null && !success) return resolve(false); - Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`).then(response => { + Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`, true).then(response => { if (response.ok) { loggedInUser.lastSessionSlot = -1; return resolve(true); @@ -795,7 +795,7 @@ export class GameData { link.remove(); }; if (!bypassLogin && dataType < GameDataType.SETTINGS) { - Utils.apiFetch(`savedata/get?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`) + Utils.apiFetch(`savedata/get?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`, true) .then(response => response.text()) .then(response => { if (!response.length || response[0] !== '{') { diff --git a/src/utils.ts b/src/utils.ts index acd81f4f757..3cbbfd84263 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -233,11 +233,15 @@ export function getCookie(cName: string): string { return ''; } -export function apiFetch(path: string): Promise { +export function apiFetch(path: string, authed: boolean = false): Promise { return new Promise((resolve, reject) => { - const sId = getCookie(sessionIdKey); - const headers = sId ? { 'Authorization': sId } : {}; - fetch(`${apiUrl}/${path}`, { headers: headers }) + const request = {}; + if (authed) { + const sId = getCookie(sessionIdKey); + if (sId) + request['headers'] = { 'Authorization': sId }; + } + fetch(`${apiUrl}/${path}`, request) .then(response => resolve(response)) .catch(err => reject(err)); });