From 6fb6c574bde89ee6f2c0f771c79e408ce6a1fed2 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 20 Oct 2023 22:04:05 +0100 Subject: [PATCH] i hate uri's --- src/utils/scoresaber/api.ts | 6 ++---- src/utils/string.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils/scoresaber/api.ts b/src/utils/scoresaber/api.ts index 8b38ea1..e6330d7 100644 --- a/src/utils/scoresaber/api.ts +++ b/src/utils/scoresaber/api.ts @@ -29,7 +29,7 @@ export async function searchByName( name: string, ): Promise { const response = await fetchQueue.fetch( - encodeURIComponent(formatString(SEARCH_PLAYER_URL, name)), + formatString(SEARCH_PLAYER_URL, name), ); const json = await response.json(); @@ -95,9 +95,7 @@ export async function fetchScores( limit = 100; } const response = await fetchQueue.fetch( - encodeURIComponent( - formatString(PLAYER_SCORES, playerId, limit, searchType, page), - ), + formatString(PLAYER_SCORES, playerId, limit, searchType, page), ); const json = await response.json(); diff --git a/src/utils/string.ts b/src/utils/string.ts index 08b8ea2..a3aa3cd 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -2,10 +2,15 @@ * Formats a string with the given arguments. * * @param str the string to check + * @param uriEncodeStrings whether to uri encode the strings * @param args the arguments to replace * @returns the formatted string */ -export function formatString(str: string, ...args: any[]): string { +export function formatString( + str: string, + uriEncodeStrings: boolean, + ...args: any[] +): string { return str.replace(/{}/g, (match) => { // If there are no arguments, return the match if (args.length === 0) { @@ -13,6 +18,9 @@ export function formatString(str: string, ...args: any[]): string { } // Otherwise, return the next argument + if (uriEncodeStrings) { + return encodeURIComponent(String(args.shift())); + } return String(args.shift()); }); }