i hate uri's
Some checks failed
deploy / deploy (push) Failing after 22s

This commit is contained in:
Lee 2023-10-20 22:04:05 +01:00
parent f418ac9388
commit 6fb6c574bd
2 changed files with 11 additions and 5 deletions

@ -29,7 +29,7 @@ export async function searchByName(
name: string,
): Promise<ScoresaberPlayer[] | undefined> {
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();

@ -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());
});
}