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

29 lines
955 B
TypeScript
Raw Normal View History

2025-10-12 15:05:58 +00:00
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";
2023-11-07 18:58:19 -06:00
export async function getRatingLeague(
2023-11-07 18:58:19 -06:00
region: Region,
league: number,
2025-10-12 15:05:58 +00:00
usePatientFetcher = false
2023-11-07 18:58:19 -06:00
) {
const fetcher = (url: string) =>
usePatientFetcher
2025-10-12 15:05:58 +00:00
? patientFetch(url, undefined, { cache: "no-store" })
: fetch(url, { cache: "no-store" });
2023-11-07 18:58:19 -06:00
const response = await fetcher(
2025-10-12 15:05:58 +00:00
context === "website"
? `/api/${region}/rating/current/league/${league}`
2023-11-11 21:37:59 -06:00
: `https://${regionToRegionSubdomain(
2025-10-12 15:05:58 +00:00
region
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`
2023-11-07 18:58:19 -06:00
);
const json = await response.json();
2023-11-07 18:58:19 -06:00
2025-10-12 15:05:58 +00:00
return context === "website"
? (json as RatingPlayer[])
: (json as LeagueTop).result;
2023-11-07 18:58:19 -06:00
}