mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-03 04:18:16 +03:00
Change URLs to use the JS URL constructor consistently across codebase.
Fixes #281
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export function CreateURLWithParams(url: string, params: Record<string, string>) {
|
||||
const u = new URL(url);
|
||||
|
||||
for (const key in params) {
|
||||
u.searchParams.set(key, params[key]);
|
||||
}
|
||||
|
||||
return u;
|
||||
}
|
||||
Reference in New Issue
Block a user