mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { Region } from '../../constants/regions';
|
|
import { AllStats } from '../blitz/getAccountInfo';
|
|
|
|
export interface IndividualPlayerStats {
|
|
clan: { clan_id: number; name: string; tag: string };
|
|
statistics: {
|
|
all: AllStats;
|
|
wn8: number;
|
|
wn7: number;
|
|
average_tier: number;
|
|
};
|
|
last_battle_time: number;
|
|
nickname: string;
|
|
account_id: number;
|
|
achievements: {
|
|
account_id: number;
|
|
[key: string]: number;
|
|
};
|
|
region: Region;
|
|
}
|
|
|
|
export type PlayerStats = IndividualPlayerStats[];
|
|
|
|
export async function getPlayerStats<
|
|
Ids extends number | number[],
|
|
ReturnType = Ids extends number ? PlayerStats : PlayerStats[],
|
|
>(region: Region, ids: Ids) {
|
|
const stats = await Promise.all(
|
|
((typeof ids === 'number' ? [ids] : ids) as number[]).map((id) =>
|
|
fetch(`https://www.blitzstars.com/api/playerstats/${id}`).then(
|
|
(response) => response.json() as Promise<PlayerStats>,
|
|
),
|
|
),
|
|
);
|
|
|
|
if (typeof ids === 'number') return stats[0] as ReturnType;
|
|
return stats as ReturnType;
|
|
}
|