2024-03-20 17:33:21 -05:00
|
|
|
import { RatingInfo } from '../../commands/ratingLeaderboard';
|
2023-08-09 17:20:03 +00:00
|
|
|
import { Region } from '../../constants/regions';
|
2024-04-20 12:00:48 -05:00
|
|
|
import { context } from '../blitzrinth/context';
|
|
|
|
|
import { patientFetch } from '../blitzrinth/patientFetch';
|
2023-08-09 17:20:03 +00:00
|
|
|
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
|
|
|
|
|
2024-03-20 17:33:21 -05:00
|
|
|
const cache: Partial<Record<Region, RatingInfo>> = {};
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2024-03-20 17:33:21 -05:00
|
|
|
export default async function getRatingInfo(region: Region) {
|
|
|
|
|
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-11-14 07:34:47 -06:00
|
|
|
{ cache: 'no-store' },
|
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
|
|
|
}
|