mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 05:06:11 +01:00
30 lines
955 B
TypeScript
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;
|
|
}
|