From 74a49bca56dc2979dc1a3d5eb421fe267eea02f0 Mon Sep 17 00:00:00 2001 From: Razzmatazz Date: Mon, 16 Sep 2024 11:17:11 -0500 Subject: [PATCH] use url searchparam for profile request --- src/modules/player-stats.mjs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/modules/player-stats.mjs b/src/modules/player-stats.mjs index e11c94c6..821b2029 100644 --- a/src/modules/player-stats.mjs +++ b/src/modules/player-stats.mjs @@ -5,15 +5,12 @@ const requestMethod = 'GET'; const playerStats = { useTurnstile: false, - request: async (path, gameMode, body) => { + request: async (path, body) => { try { const method = body ? 'POST' : 'GET'; const response = await fetch(apiUrl + path, { method, body, - headers: { - 'game-mode': gameMode, - } }); if (response.status !== 200) { @@ -46,16 +43,16 @@ const playerStats = { // Create a form request to send the Turnstile token // This avoids sending an extra pre-flight request let body; - let searchParams = ''; + let searchParams = `?gameMode=${gameMode}`; if (turnstileToken) { if (requestMethod === 'POST') { body = new FormData(); body.append('Turnstile-Token', turnstileToken); } else { - searchParams = `?token=${turnstileToken}`; + searchParams += `&token=${turnstileToken}`; } } - return playerStats.request(`/name/${searchString}${searchParams}`, gameMode, body).catch(error => { + return playerStats.request(`/name/${searchString}${searchParams}`, body).catch(error => { if (error.message.includes('Malformed')) { return Promise.reject(new Error('Error searching player profile; try removing one character from the end until the search works.')); } @@ -64,16 +61,16 @@ const playerStats = { }, getProfile: async (accountId, gameMode = 'regular', turnstileToken) => { let body; - let searchParams = ''; + let searchParams = `?gameMode=${gameMode}`; if (turnstileToken) { if (requestMethod === 'POST') { body = new FormData(); body.append('Turnstile-Token', turnstileToken); } else { - searchParams = `?token=${turnstileToken}`; + searchParams += `&token=${turnstileToken}`; } } - return playerStats.request(`/account/${accountId}${searchParams}`, gameMode, body); + return playerStats.request(`/account/${accountId}${searchParams}`, body); }, };