2024-09-07 23:00:56 -05:00
|
|
|
import { RatingInfo, Region } from '@blitzkit/core';
|
2024-09-08 10:11:24 -05:00
|
|
|
import { regionToRegionSubdomain } from '../../../website/src/core/blitz/regionToRegionSubdomain';
|
|
|
|
|
import { context } from '../../../website/src/core/blitzkit/context';
|
|
|
|
|
import { patientFetch } from '../../../website/src/core/blitzkit/patientFetch';
|
2023-08-09 17:20:03 +00:00
|
|
|
|
2024-03-20 17:33:21 -05:00
|
|
|
const cache: Partial<Record<Region, RatingInfo>> = {};
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2024-09-08 10:11:24 -05:00
|
|
|
export async function getRatingInfo(region: Region) {
|
2024-03-20 17:33:21 -05:00
|
|
|
if (cache[region]) return cache[region]!;
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2023-11-14 13:42:15 -06:00
|
|
|
const response = await patientFetch(
|
2023-11-11 21:37:59 -06:00
|
|
|
context === 'website'
|
2024-03-20 17:33:21 -05:00
|
|
|
? `/api/${region}/rating/current/info`
|
2023-11-11 21:37:59 -06:00
|
|
|
: `https://${regionToRegionSubdomain(
|
|
|
|
|
region,
|
|
|
|
|
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
2023-11-14 13:42:15 -06:00
|
|
|
undefined,
|
2023-08-09 17:20:03 +00:00
|
|
|
);
|
2024-03-20 17:33:21 -05:00
|
|
|
const data = (await response.json()) as RatingInfo;
|
2023-09-03 18:15:10 +00:00
|
|
|
|
2024-03-20 17:33:21 -05:00
|
|
|
cache[region] = data;
|
2024-01-19 16:02:03 -06:00
|
|
|
|
|
|
|
|
return data;
|
2023-08-09 17:20:03 +00:00
|
|
|
}
|