2024-03-20 17:33:21 -05:00
|
|
|
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';
|
|
|
|
|
|
2024-03-20 17:33:21 -05:00
|
|
|
export async function getRatingLeague(
|
2023-11-07 18:58:19 -06:00
|
|
|
region: Region,
|
|
|
|
|
league: number,
|
|
|
|
|
usePatientFetcher = false,
|
|
|
|
|
) {
|
2023-11-16 11:13:51 -06:00
|
|
|
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'
|
2024-03-20 17:33:21 -05:00
|
|
|
? `/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
|
|
|
);
|
2023-11-16 11:13:51 -06:00
|
|
|
const json = await response.json();
|
2023-11-07 18:58:19 -06:00
|
|
|
|
2023-11-16 11:13:51 -06:00
|
|
|
return context === 'website'
|
2024-03-20 17:33:21 -05:00
|
|
|
? (json as RatingPlayer[])
|
2023-11-16 11:13:51 -06:00
|
|
|
: (json as LeagueTop).result;
|
2023-11-07 18:58:19 -06:00
|
|
|
}
|