2024-11-20 10:50:09 -06:00
|
|
|
import { RatingLeague, RatingReward, Region } from '@blitzkit/core';
|
|
|
|
|
import { context } from '../blitzkit/context';
|
|
|
|
|
import { patientFetch } from '../blitzkit/patientFetch';
|
|
|
|
|
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
2023-08-09 17:20:03 +00:00
|
|
|
|
2024-11-20 10:50:09 -06:00
|
|
|
export type RatingInfo =
|
|
|
|
|
| {
|
|
|
|
|
detail: undefined;
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2024-11-20 10:50:09 -06:00
|
|
|
title: string;
|
|
|
|
|
icon: string | null;
|
|
|
|
|
start_at: string;
|
|
|
|
|
finish_at: string;
|
|
|
|
|
current_season: number;
|
|
|
|
|
updated_at: string;
|
|
|
|
|
count: number;
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2024-11-20 10:50:09 -06:00
|
|
|
rewards: RatingReward[];
|
|
|
|
|
leagues: RatingLeague[];
|
|
|
|
|
}
|
|
|
|
|
| { detail: { error: string } };
|
2023-09-03 18:15:10 +00:00
|
|
|
|
2024-11-20 10:50:09 -06:00
|
|
|
const cache: Partial<Record<Region, RatingInfo>> = {};
|
2024-01-19 16:02:03 -06:00
|
|
|
|
2024-11-20 10:50:09 -06:00
|
|
|
export 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,
|
|
|
|
|
);
|
|
|
|
|
const data = (await response.json()) as RatingInfo;
|
|
|
|
|
|
|
|
|
|
cache[region] = data;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|