mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02: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;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { environmentConfig } from "@blitzkit/core";
|
||||
|
||||
export function alias(alias: string, path: string) {
|
||||
const environment = environmentConfig();
|
||||
|
||||
if (!(alias in environment.aliases)) {
|
||||
throw new Error(`Invalid alias "${alias}"`);
|
||||
}
|
||||
|
||||
const base = environment.aliases[alias];
|
||||
|
||||
return `${base}${path}`;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { alias } from "@blitzkit/core";
|
||||
import { fetchPB } from "../../protobuf";
|
||||
import {
|
||||
CamouflageDefinitions,
|
||||
@@ -14,38 +15,50 @@ import { BlitzKitAPI } from "./base";
|
||||
|
||||
export class ClientBlitzKitAPI extends BlitzKitAPI {
|
||||
gameDefinitions() {
|
||||
return fetchPB("/api/definitions/game.pb", GameDefinitions);
|
||||
return fetchPB(alias("api", "/definitions/game.pb"), GameDefinitions);
|
||||
}
|
||||
|
||||
consumableDefinitions() {
|
||||
return fetchPB("/api/definitions/consumables.pb", ConsumableDefinitions);
|
||||
return fetchPB(
|
||||
alias("api", "/definitions/consumables.pb"),
|
||||
ConsumableDefinitions,
|
||||
);
|
||||
}
|
||||
|
||||
tankDefinitions() {
|
||||
return fetchPB("/api/definitions/tanks.pb", TankDefinitions);
|
||||
return fetchPB(alias("api", "/definitions/tanks.pb"), TankDefinitions);
|
||||
}
|
||||
|
||||
camouflageDefinitions() {
|
||||
return fetchPB("/api/definitions/camouflage.pb", CamouflageDefinitions);
|
||||
return fetchPB(
|
||||
alias("api", "/definitions/camouflage.pb"),
|
||||
CamouflageDefinitions,
|
||||
);
|
||||
}
|
||||
|
||||
provisionDefinitions() {
|
||||
return fetchPB("/api/definitions/provisions.pb", ProvisionDefinitions);
|
||||
return fetchPB(
|
||||
alias("api", "/definitions/provisions.pb"),
|
||||
ProvisionDefinitions,
|
||||
);
|
||||
}
|
||||
|
||||
modelDefinitions() {
|
||||
return fetchPB("/api/definitions/models.pb", ModelDefinitions);
|
||||
return fetchPB(alias("api", "/definitions/models.pb"), ModelDefinitions);
|
||||
}
|
||||
|
||||
skillDefinitions() {
|
||||
return fetchPB("/api/definitions/skills.pb", SkillDefinitions);
|
||||
return fetchPB(alias("api", "/definitions/skills.pb"), SkillDefinitions);
|
||||
}
|
||||
|
||||
equipmentDefinitions() {
|
||||
return fetchPB("/api/definitions/equipment.pb", EquipmentDefinitions);
|
||||
return fetchPB(
|
||||
alias("api", "/definitions/equipment.pb"),
|
||||
EquipmentDefinitions,
|
||||
);
|
||||
}
|
||||
|
||||
galleryDefinitions() {
|
||||
return fetchPB("/api/definitions/gallery.pb", Gallery);
|
||||
return fetchPB(alias("api", "/definitions/gallery.pb"), Gallery);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Avatar, fetchGlossary, Gallery } from "@blitzkit/core";
|
||||
import { ServerBlitzKitAPI9 } from "@blitzkit/core/src/blitzkit/api/server/9_gameDefinitions";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { extname } from "path";
|
||||
import { Cache } from "./0_base";
|
||||
import { ServerBlitzKitAPI9 } from "./9_gameDefinitions";
|
||||
|
||||
export abstract class ServerBlitzKitAPI10 extends ServerBlitzKitAPI9 {
|
||||
@Cache()
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { assertSecret } from "@blitzkit/core";
|
||||
|
||||
interface EnvironmentConfig {
|
||||
paths: Record<string, string | null>;
|
||||
nodes: Record<string, string>;
|
||||
aliases: Record<string, string>;
|
||||
}
|
||||
|
||||
export const environments = import.meta.glob(
|
||||
"../../../../environments/*.json",
|
||||
{
|
||||
eager: true,
|
||||
import: "default",
|
||||
},
|
||||
) as Record<string, EnvironmentConfig>;
|
||||
const root = "../../../../environments";
|
||||
|
||||
for (const key in environments) {
|
||||
const trimmed = key.slice(root.length + 1, -5);
|
||||
|
||||
environments[trimmed] = environments[key];
|
||||
delete environments[key];
|
||||
}
|
||||
|
||||
export function environmentConfig() {
|
||||
const environment = assertSecret(import.meta.env.ENVIRONMENT);
|
||||
|
||||
if (!(environment in environments)) {
|
||||
throw new Error(`Invalid environment "${environment}"`);
|
||||
}
|
||||
|
||||
return environments[environment];
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import { getRatingInfo } from "../blitz/getRatingInfo";
|
||||
import { assertSecret } from "./assertSecret";
|
||||
|
||||
interface GitHubTrees {
|
||||
tree: { path: string; url: string }[];
|
||||
}
|
||||
|
||||
let cachedLatestArchivedSeasonNumber: number | null = null;
|
||||
|
||||
export async function getArchivedLatestSeasonNumber() {
|
||||
if (cachedLatestArchivedSeasonNumber !== null) {
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
|
||||
const ratingInfo = await getRatingInfo("com");
|
||||
|
||||
if (ratingInfo.detail) {
|
||||
const regionsURL = (
|
||||
(await fetch(
|
||||
`https://api.github.com/repos/${assertSecret(
|
||||
import.meta.env.PUBLIC_ASSET_REPO
|
||||
)}/git/trees/main`
|
||||
).then((response) => response.json())) as GitHubTrees
|
||||
).tree.find(({ path }) => path === "regions")!.url;
|
||||
const comURL = (
|
||||
(await fetch(regionsURL).then((response) =>
|
||||
response.json()
|
||||
)) as GitHubTrees
|
||||
).tree.find(({ path }) => path === "com")!.url;
|
||||
const ratingURL = (
|
||||
(await fetch(comURL).then((response) => response.json())) as {
|
||||
tree: [{ url: string }];
|
||||
}
|
||||
).tree[0].url;
|
||||
const latestSeason = Math.max(
|
||||
...(
|
||||
(await fetch(ratingURL).then((response) => response.json())) as {
|
||||
tree: { path: string }[];
|
||||
}
|
||||
).tree.map(({ path }) => Number(path))
|
||||
);
|
||||
|
||||
cachedLatestArchivedSeasonNumber = latestSeason;
|
||||
} else {
|
||||
cachedLatestArchivedSeasonNumber = ratingInfo.current_season - 1;
|
||||
}
|
||||
|
||||
return cachedLatestArchivedSeasonNumber;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// import { RatingInfo, Region, asset } from '@blitzkit/core';
|
||||
|
||||
// const cache: Record<
|
||||
// Region,
|
||||
// Record<
|
||||
// number,
|
||||
// RatingInfo & {
|
||||
// detail: undefined;
|
||||
// }
|
||||
// >
|
||||
// > = {
|
||||
// com: {},
|
||||
// eu: {},
|
||||
// asia: {},
|
||||
// };
|
||||
|
||||
// export async function getArchivedRatingInfo(region: Region, season: number) {
|
||||
// if (!cache[region][season]) {
|
||||
// const info = await fetch(
|
||||
// asset(`regions/${region}/rating/${season}/info.cdon.lz4`),
|
||||
// )
|
||||
// .then((response) => response.arrayBuffer())
|
||||
// .then((buffer) =>
|
||||
// superDecompress<RatingInfo & { detail: undefined }>(buffer),
|
||||
// );
|
||||
// cache[region][season] = info;
|
||||
// }
|
||||
|
||||
// return cache[region][season];
|
||||
// }
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./alias";
|
||||
export * from "./assertSecret";
|
||||
export * from "./availableProvisions";
|
||||
export * from "./averageDefinitions";
|
||||
@@ -7,6 +8,7 @@ export * from "./createDefaultSkills";
|
||||
export * from "./degressiveStat";
|
||||
export * from "./discoveredIdDefinitions";
|
||||
export * from "./emblemURL";
|
||||
export * from "./environment";
|
||||
export * from "./eventManager";
|
||||
export * from "./getTimeDaysAgo";
|
||||
export * from "./isExplosive";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { alias } from "@blitzkit/core";
|
||||
|
||||
export const BLITZKIT_TANK_ICON_SIZE = { width: 40 * 16, height: 30 * 16 };
|
||||
|
||||
export function tankIcon(id: number, size: "big" | "small" = "big") {
|
||||
return `/api/tanks/${id}/icons/${size}.webp`;
|
||||
return alias("api", `/tanks/${id}/icons/${size}.webp`);
|
||||
}
|
||||
Reference in new issue
Block a user