diff --git a/server/src/lib/score-import/import-types/api/arc-iidx/class-handler.ts b/server/src/lib/score-import/import-types/api/arc-iidx/class-handler.ts index b79e23763..07e39b6e7 100644 --- a/server/src/lib/score-import/import-types/api/arc-iidx/class-handler.ts +++ b/server/src/lib/score-import/import-types/api/arc-iidx/class-handler.ts @@ -3,6 +3,8 @@ import { HasOwnProperty } from "utils/misc"; import { IIDXDans } from "lib/constants/classes"; import { ClassHandler } from "../../../framework/user-game-stats/types"; import { ServerConfig } from "lib/setup/config"; +import { CreateURLWithParams } from "utils/url"; +import { profile } from "console"; export async function CreateArcIIDXClassHandler( profileID: string, @@ -16,14 +18,15 @@ export async function CreateArcIIDXClassHandler( // SP and DP dans are located in the same place, // fetch once, then return a function that traverses this data. try { - const res = await fetch( - `${ServerConfig.ARC_API_URL}/api/v1/iidx/27/profiles?_id=${profileID}`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); + const url = CreateURLWithParams(`${ServerConfig.ARC_API_URL}/api/v1/iidx/27/profiles`, { + _id: profileID, + }); + + const res = await fetch(url.href, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); json = await res.json(); } catch (e) { diff --git a/server/src/lib/score-import/import-types/common/api-kai/reauth.ts b/server/src/lib/score-import/import-types/common/api-kai/reauth.ts index a1ae7e3e3..8087dc512 100644 --- a/server/src/lib/score-import/import-types/common/api-kai/reauth.ts +++ b/server/src/lib/score-import/import-types/common/api-kai/reauth.ts @@ -5,6 +5,7 @@ import { GetKaiTypeClientCredentials, KaiTypeToBaseURL } from "./utils"; import nodeFetch from "utils/fetch"; import p from "prudence"; import { KaiAuthDocument } from "tachi-common"; +import { CreateURLWithParams } from "utils/url"; const REAUTH_SCHEMA = { access_token: "string", @@ -35,11 +36,14 @@ export function CreateKaiReauthFunction( return async () => { let res; try { - res = await fetch( - `${KaiTypeToBaseURL(kaiType)}/oauth/token?refresh_token=${ - authDoc.refreshToken - }&grant_type=refresh_token&client_secret=${CLIENT_SECRET}&client_id=${CLIENT_ID}` - ); + const url = CreateURLWithParams(`${KaiTypeToBaseURL(kaiType)}/oauth/token`, { + refresh_token: authDoc.refreshToken, + grant_type: "refresh_token", + client_secret: CLIENT_SECRET, + client_id: CLIENT_ID, + }); + + res = await fetch(url.href); } catch (err) { logger.error(`Unexpected error while fetching reauth?`, { res, err }); throw new ScoreImportFatalError( diff --git a/server/src/server/router/api/v1/auth/auth.ts b/server/src/server/router/api/v1/auth/auth.ts index 9f14d2868..cd91701f6 100644 --- a/server/src/server/router/api/v1/auth/auth.ts +++ b/server/src/server/router/api/v1/auth/auth.ts @@ -7,6 +7,7 @@ import { FormatUserDoc } from "utils/user"; import nodeFetch from "utils/fetch"; import { Random20Hex } from "utils/misc"; import { ServerConfig } from "lib/setup/config"; +import { CreateURLWithParams } from "utils/url"; const logger = CreateLogCtx(__filename); @@ -105,9 +106,13 @@ export async function ValidateCaptcha( remoteAddr: string | undefined, fetch = nodeFetch ) { - const r = await fetch( - `https://www.google.com/recaptcha/api/siteverify?secret=${ServerConfig.CAPTCHA_SECRET_KEY}&response=${recaptcha}&remoteip=${remoteAddr}` - ); + const url = CreateURLWithParams(`https://www.google.com/recaptcha/api/siteverify`, { + secret: ServerConfig.CAPTCHA_SECRET_KEY, + response: recaptcha, + remoteip: remoteAddr ?? "", + }); + + const r = await fetch(url.href); if (r.status !== 200) { logger.verbose(`Failed GCaptcha response ${r.status}, ${r.body}`); diff --git a/server/src/utils/url.ts b/server/src/utils/url.ts new file mode 100644 index 000000000..24a94461a --- /dev/null +++ b/server/src/utils/url.ts @@ -0,0 +1,9 @@ +export function CreateURLWithParams(url: string, params: Record) { + const u = new URL(url); + + for (const key in params) { + u.searchParams.set(key, params[key]); + } + + return u; +}