mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
27 lines
866 B
TypeScript
27 lines
866 B
TypeScript
import { RatingsInfo } from '../../commands/ratings';
|
|
import { Region } from '../../constants/regions';
|
|
import { context } from '../blitzkrieg/context';
|
|
import { patientFetch } from '../blitzkrieg/patientFetch';
|
|
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
|
|
|
const ratingsInfoCache: Partial<Record<Region, RatingsInfo>> = {};
|
|
|
|
export default async function getRatingsInfo(region: Region) {
|
|
if (ratingsInfoCache[region]) return ratingsInfoCache[region]!;
|
|
|
|
const response = await patientFetch(
|
|
context === 'website'
|
|
? `/api/${region}/ratings/current/info`
|
|
: `https://${regionToRegionSubdomain(
|
|
region,
|
|
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
|
undefined,
|
|
{ cache: 'no-store' },
|
|
);
|
|
const data = (await response.json()) as RatingsInfo;
|
|
|
|
ratingsInfoCache[region] = data;
|
|
|
|
return data;
|
|
}
|