Files
blitzkit/packages/core/src/blitz/getRatingInfo.ts
T

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-10-12 15:05:58 +00:00
import { context } from "../blitzkit/context";
import { patientFetch } from "../blitzkit/patientFetch";
2025-10-13 23:20:26 -05:00
import type { RatingLeague, RatingReward } from "./rating";
import type { Region } from "./regions";
2025-10-12 15:05:58 +00:00
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
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(
2025-10-12 15:05:58 +00:00
context === "website"
2024-11-20 10:50:09 -06:00
? `/api/${region}/rating/current/info`
: `https://${regionToRegionSubdomain(
2025-10-12 15:05:58 +00:00
region
2024-11-20 10:50:09 -06:00
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
2025-10-12 15:05:58 +00:00
undefined
2024-11-20 10:50:09 -06:00
);
const data = (await response.json()) as RatingInfo;
cache[region] = data;
return data;
}