Files
blitzkit/packages/core/src/blitz/getRatingLeague.ts
T
2025-10-12 15:05:58 +00:00

30 lines
955 B
TypeScript

import { context } from "../blitzkit/context";
import { patientFetch } from "../blitzkit/patientFetch";
import { RatingPlayer } from "../statistics";
import { LeagueTop } from "./rating";
import { Region } from "./regions";
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
export async function getRatingLeague(
region: Region,
league: number,
usePatientFetcher = false
) {
const fetcher = (url: string) =>
usePatientFetcher
? patientFetch(url, undefined, { cache: "no-store" })
: fetch(url, { cache: "no-store" });
const response = await fetcher(
context === "website"
? `/api/${region}/rating/current/league/${league}`
: `https://${regionToRegionSubdomain(
region
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`
);
const json = await response.json();
return context === "website"
? (json as RatingPlayer[])
: (json as LeagueTop).result;
}