fix: port to core 1

This commit is contained in:
TrèsAbhi committed 2024-09-08 10:24:48 -05:00
1 parent fd2e2f9c7b
commit 5e989a16bc
24 files changed
+24 -14

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import { Region, assertSecret, idToRegion } from '@blitzkit/core';
export async function isValidBlitzId(id: number, token?: string) {
let region: Region;
try {
region = idToRegion(id);
} catch (error) {
return false;
}
const json = await fetch(
`https://api.wotblitz.${region}/wotb/account/info/?account_id=${id}&application_id=${assertSecret(
process.env.NEXT_PUBLIC_WARGAMING_APPLICATION_ID,
)}${
token === undefined ? '' : `&access_token=${token}`
}&fields=account_id%2C-account_id`,
).then(
(response) =>
response.json() as Promise<
| {
status: 'ok';
data: Record<number, {} | null>;
}
| { status: 'error' }
>,
);
return json.status === 'ok' && json.data[id] !== null;
}