Files
blitzkit/src/core/blitz/getRatingLeague.ts
T

28 lines
964 B
TypeScript
Raw Normal View History

import { LeagueTop, RatingPlayer } from '../../commands/ratingLeaderboard';
2023-11-07 18:58:19 -06:00
import { Region } from '../../constants/regions';
2023-11-11 21:37:59 -06:00
import { context } from '../blitzkrieg/context';
2023-11-07 18:58:19 -06:00
import { patientFetch } from '../blitzkrieg/patientFetch';
import regionToRegionSubdomain from './regionToRegionSubdomain';
export async function getRatingLeague(
2023-11-07 18:58:19 -06:00
region: Region,
league: number,
usePatientFetcher = false,
) {
const fetcher = (url: string) =>
usePatientFetcher
? patientFetch(url, undefined, { cache: 'no-store' })
: fetch(url, { cache: 'no-store' });
2023-11-07 18:58:19 -06:00
const response = await fetcher(
2023-11-11 21:37:59 -06:00
context === 'website'
? `/api/${region}/rating/current/league/${league}`
2023-11-11 21:37:59 -06:00
: `https://${regionToRegionSubdomain(
region,
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`,
2023-11-07 18:58:19 -06:00
);
const json = await response.json();
2023-11-07 18:58:19 -06:00
return context === 'website'
? (json as RatingPlayer[])
: (json as LeagueTop).result;
2023-11-07 18:58:19 -06:00
}