mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-26 20:19:50 +01:00
aliases
This commit is contained in:
1 parent
13cda7aec0
commit
b26c5137f3
53 files changed
+236
-932
No files matched your search
@@ -1,5 +0,0 @@
|
||||
import { LEAGUES } from "./rating";
|
||||
|
||||
export function getLeagueFromScore(score: number) {
|
||||
return LEAGUES.find(({ minScore }) => score >= minScore)!;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import type { RatingLeague, RatingReward } from "./rating";
|
||||
import type { Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
export type RatingInfo =
|
||||
| {
|
||||
detail: undefined;
|
||||
|
||||
title: string;
|
||||
icon: string | null;
|
||||
start_at: string;
|
||||
finish_at: string;
|
||||
current_season: number;
|
||||
updated_at: string;
|
||||
count: number;
|
||||
|
||||
rewards: RatingReward[];
|
||||
leagues: RatingLeague[];
|
||||
}
|
||||
| { detail: { error: string } };
|
||||
|
||||
const cache: Partial<Record<Region, RatingInfo>> = {};
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import type { RatingPlayer } from "../statistics";
|
||||
import type { LeagueTop } from "./rating";
|
||||
import type { 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;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { patientFetch } from "../blitzkit/patientFetch";
|
||||
import { withCORSProxy } from "../blitzkit/withCORSProxy";
|
||||
import type { RatingNeighbors } from "./rating";
|
||||
import type { Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
export async function getRatingNeighbors(
|
||||
region: Region,
|
||||
id: number,
|
||||
count: number,
|
||||
usePatientFetcher = false
|
||||
) {
|
||||
const fetcher = (url: string) =>
|
||||
usePatientFetcher
|
||||
? patientFetch(url, undefined, { cache: "no-store" })
|
||||
: fetch(url, { cache: "no-store" });
|
||||
const response = await fetcher(
|
||||
withCORSProxy(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`
|
||||
)
|
||||
);
|
||||
const json = (await response.json()) as RatingNeighbors;
|
||||
|
||||
return json;
|
||||
}
|
||||
@@ -10,13 +10,8 @@ export * from "./getAccountAchievements";
|
||||
export * from "./getAccountInfo";
|
||||
export * from "./getClanAccountInfo";
|
||||
export * from "./getClanInfo";
|
||||
export * from "./getLeagueFromScore";
|
||||
export * from "./getRatingInfo";
|
||||
export * from "./getRatingLeague";
|
||||
export * from "./getRatingNeighbors";
|
||||
export * from "./getTankStats";
|
||||
export * from "./idToRegion";
|
||||
export * from "./isOnGoingRatingSeason";
|
||||
export * from "./isValidBlitzId";
|
||||
export * from "./nations";
|
||||
export * from "./normalizeExtra";
|
||||
@@ -28,6 +23,5 @@ export * from "./regions";
|
||||
export * from "./regionSubdomainToRegion";
|
||||
export * from "./regionToRegionSubdomain";
|
||||
export * from "./searchClansAcrossRegions";
|
||||
export * from "./searchCurrentRatingPlayers";
|
||||
export * from "./searchPlayersAcrossRegions";
|
||||
export * from "./toUniqueId";
|
||||
@@ -1,6 +0,0 @@
|
||||
import { getRatingInfo } from "./getRatingInfo";
|
||||
|
||||
export async function isOnGoingRatingSeason() {
|
||||
const ratingInfo = await getRatingInfo("com");
|
||||
return ratingInfo.detail === undefined;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { context } from "../blitzkit/context";
|
||||
import { type Region } from "./regions";
|
||||
import { regionToRegionSubdomain } from "./regionToRegionSubdomain";
|
||||
|
||||
type CurrentRatingPlayerSearch = Record<
|
||||
number,
|
||||
{
|
||||
spa_id: number;
|
||||
nickname: string;
|
||||
clan_tag: string;
|
||||
} & (
|
||||
| {
|
||||
skip: true;
|
||||
}
|
||||
| {
|
||||
skip: false;
|
||||
mmr: number;
|
||||
season_number: number;
|
||||
calibrationBattlesLeft: number;
|
||||
number: number;
|
||||
updated_at: string;
|
||||
neighbors: [];
|
||||
}
|
||||
)
|
||||
>;
|
||||
|
||||
export async function searchCurrentRatingPlayers(region: Region, name: string) {
|
||||
const encodedSearch = encodeURIComponent(name);
|
||||
const response = await fetch(
|
||||
context === "website"
|
||||
? `/api/${region}/rating/current/search/${encodedSearch}`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/search/?prefix=${encodedSearch}`,
|
||||
{ cache: "no-store" }
|
||||
);
|
||||
const accountList = (await response.json()) as CurrentRatingPlayerSearch;
|
||||
|
||||
return accountList;
|
||||
}
|
||||
Reference in new issue
Block a user