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