2025-10-12 15:05:58 +00:00
|
|
|
import { assertSecret } from "../blitzkit";
|
|
|
|
|
import { idToRegion } from "./idToRegion";
|
|
|
|
|
import { Region } from "./regions";
|
2024-09-01 15:46:39 -05:00
|
|
|
|
|
|
|
|
export async function isValidBlitzId(id: number, token?: string) {
|
|
|
|
|
let region: Region;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
region = idToRegion(id);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const json = await fetch(
|
2024-09-07 21:45:00 -05:00
|
|
|
`https://api.wotblitz.${region}/wotb/account/info/?account_id=${id}&application_id=${assertSecret(
|
2025-10-12 15:05:58 +00:00
|
|
|
import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID
|
2024-09-07 21:45:00 -05:00
|
|
|
)}${
|
2025-10-12 15:05:58 +00:00
|
|
|
token === undefined ? "" : `&access_token=${token}`
|
|
|
|
|
}&fields=account_id%2C-account_id`
|
2024-09-01 15:46:39 -05:00
|
|
|
).then(
|
|
|
|
|
(response) =>
|
|
|
|
|
response.json() as Promise<
|
|
|
|
|
| {
|
2025-10-12 15:05:58 +00:00
|
|
|
status: "ok";
|
2024-09-01 15:46:39 -05:00
|
|
|
data: Record<number, {} | null>;
|
|
|
|
|
}
|
2025-10-12 15:05:58 +00:00
|
|
|
| { status: "error" }
|
|
|
|
|
>
|
2024-09-01 15:46:39 -05:00
|
|
|
);
|
|
|
|
|
|
2025-10-12 15:05:58 +00:00
|
|
|
return json.status === "ok" && json.data[id] !== null;
|
2024-09-01 15:46:39 -05:00
|
|
|
}
|