mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: more imports
This commit is contained in:
1 parent
25cfb7db74
commit
4f24db0956
182 files changed
+456
-452
No files matched your search
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
PitchLimits,
|
||||
YawLimits,
|
||||
} from '@blitzkit/core/src/blitzkit/modelDefinitions';
|
||||
import { normalizeAngleRad } from '@blitzkit/core/src/math/normalizeAngleRad';
|
||||
import { normalizeAngleRad, PitchLimits, YawLimits } from '@blitzkit/core';
|
||||
import { clamp } from 'lodash';
|
||||
import { degToRad } from 'three/src/math/MathUtils';
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { assertSecret, Region } from '@blitzkit/core';
|
||||
import { EventManager } from '@blitzkit/core/src/blitzkit/eventManager';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
|
||||
const RETRY_ERRORS = ['REQUEST_LIMIT_EXCEEDED', 'SOURCE_NOT_AVAILABLE'];
|
||||
|
||||
export const retryAbleBlitzFetchEvent = new EventManager();
|
||||
export const blitzFetchQueueAvailableEvent = new EventManager();
|
||||
|
||||
type BlitzResponse<Data extends object> =
|
||||
| {
|
||||
status: 'error';
|
||||
error: { field: string; message: string; code: 402; value: null };
|
||||
}
|
||||
| {
|
||||
status: 'ok';
|
||||
data: Data;
|
||||
};
|
||||
|
||||
const MAX_CALLS_PER_SECOND = 10;
|
||||
|
||||
const queue: { url: string; resolve: (data: object) => void }[] = [];
|
||||
let inProgress = 0;
|
||||
|
||||
function decrement() {
|
||||
inProgress--;
|
||||
blitzFetchQueueAvailableEvent.emit(undefined);
|
||||
manageQueue();
|
||||
}
|
||||
|
||||
async function manageQueue() {
|
||||
if (queue.length > 0 && inProgress < MAX_CALLS_PER_SECOND) {
|
||||
inProgress++;
|
||||
|
||||
const timeout = setTimeout(decrement, 1000);
|
||||
const request = queue.shift()!;
|
||||
const data = (await patientFetch(request.url)
|
||||
.then((response) => response.json())
|
||||
.catch((error) => ({ status: 'error', error }))) as BlitzResponse<
|
||||
typeof request.resolve
|
||||
>;
|
||||
|
||||
if (data.status === 'ok') {
|
||||
request.resolve(data.data);
|
||||
} else {
|
||||
if (RETRY_ERRORS.includes(data.error.message)) {
|
||||
retryAbleBlitzFetchEvent.emit(undefined);
|
||||
clearTimeout(timeout);
|
||||
setTimeout(() => {
|
||||
queue.push(request);
|
||||
decrement();
|
||||
}, 1000 / MAX_CALLS_PER_SECOND);
|
||||
} else {
|
||||
clearTimeout(timeout);
|
||||
decrement();
|
||||
|
||||
throw new Error(`Wargaming response error status: "${data.status}"`, {
|
||||
cause: `Message: "${data.error.message}"\nURL: "${request.url}"`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type FetchBlitzParams = Record<string, string | number | undefined>;
|
||||
|
||||
export default function fetchBlitz<Data extends object>(
|
||||
region: Region,
|
||||
path: string,
|
||||
params: FetchBlitzParams = {},
|
||||
) {
|
||||
return new Promise<Data>((resolve) => {
|
||||
queue.push({
|
||||
url: `https://api.wotblitz.${region}/wotb/${path}/?${Object.entries({
|
||||
application_id: assertSecret(
|
||||
process.env.NEXT_PUBLIC_WARGAMING_APPLICATION_ID,
|
||||
),
|
||||
...params,
|
||||
})
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
.map(([key, value]) => `${key}=${encodeURIComponent(value!)}`)
|
||||
.join('&')}`,
|
||||
resolve(data) {
|
||||
resolve(data as Data);
|
||||
},
|
||||
});
|
||||
manageQueue();
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BlitzStats } from '@blitzkit/core';
|
||||
import calculateWN8 from '@blitzkit/core/src/statistics/calculateWN8';
|
||||
import { BlitzStats, calculateWN8 } from '@blitzkit/core';
|
||||
|
||||
export type Stat = keyof ReturnType<typeof generateStats>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
interface IndividualAccountAchievements {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { BlitzStats, Region } from '@blitzkit/core';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
import {
|
||||
FetchBlitzParams,
|
||||
fetchBlitz,
|
||||
} from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
export interface SupplementaryStats {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
type IndividualClanAccountInfo = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
import { fetchBlitz } from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
import { normalizeIds } from './normalizeIds';
|
||||
|
||||
interface IndividualClanInfo {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { LEAGUES } from '@blitzkit/core';
|
||||
|
||||
export function getLeagueFromScore(score: number) {
|
||||
return LEAGUES.find(({ minScore }) => score >= minScore)!;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { RatingInfo, Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
const cache: Partial<Record<Region, RatingInfo>> = {};
|
||||
|
||||
export default 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,9 +1,7 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { LeagueTop } from '@blitzkit/core/src/blitz/rating';
|
||||
import { RatingPlayer } from '@blitzkit/core/src/statistics/deltaBkrlBlitzStats';
|
||||
import { LeagueTop, RatingPlayer, Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingLeague(
|
||||
region: Region,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RatingNeighbors, Region } from '@blitzkit/core';
|
||||
import { patientFetch } from '../blitzkit/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkit/withCORSProxy';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingNeighbors(
|
||||
region: Region,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Region, TanksStats } from '@blitzkit/core';
|
||||
import fetchBlitz, { FetchBlitzParams } from './fetchBlitz';
|
||||
import {
|
||||
fetchBlitz,
|
||||
FetchBlitzParams,
|
||||
} from '@blitzkit/core/src/blitz/fetchBlitz';
|
||||
|
||||
export default async function getTankStats(
|
||||
export async function getTankStats(
|
||||
region: Region,
|
||||
id: number,
|
||||
params?: FetchBlitzParams,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import getRatingInfo from './getRatingInfo';
|
||||
import { getRatingInfo } from '@blitzkit/core/src/blitz/getRatingInfo';
|
||||
|
||||
export async function isOnGoingRatingSeason() {
|
||||
const ratingInfo = await getRatingInfo('com');
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export function normalizeLeagueIcon(url: string) {
|
||||
return url.startsWith('http') ? url : `https:${url}`;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Region, RegionSubdomain } from "@blitzkit/core";
|
||||
|
||||
export default function regionSubdomainToRegion(
|
||||
regionDomain: RegionSubdomain,
|
||||
): Region {
|
||||
return regionDomain === 'na' ? 'com' : regionDomain;
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Region, RegionSubdomain } from "@blitzkit/core";
|
||||
import { Region, RegionSubdomain } from '@blitzkit/core';
|
||||
|
||||
export default function regionToRegionSubdomain(
|
||||
regionDomain: Region,
|
||||
): RegionSubdomain {
|
||||
export function regionToRegionSubdomain(regionDomain: Region): RegionSubdomain {
|
||||
return regionDomain === 'com' ? 'na' : regionDomain;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { I_HAT } from '@blitzkit/core/src/math/axis';
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function rotateDavaVector(vector: Vector3) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { context } from '../blitzkit/context';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
import { regionToRegionSubdomain } from './regionToRegionSubdomain';
|
||||
|
||||
type CurrentRatingPlayerSearch = Record<
|
||||
number,
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export const usernamePattern = /^[a-zA-Z0-9_]{3,24}$/;
|
||||
export const usernamePatternWithoutPosition = /[a-zA-Z0-9_]{3,24}/;
|
||||
@@ -1,64 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import fetchBlitz from '../fetchBlitz';
|
||||
import { usernamePattern } from './constants';
|
||||
|
||||
export interface AccountListItem {
|
||||
nickname: string;
|
||||
account_id: number;
|
||||
}
|
||||
export type AccountList = AccountListItem[];
|
||||
export type AccountListWithServer = (AccountListItem & {
|
||||
region: Region;
|
||||
})[];
|
||||
|
||||
export default async function searchPlayersAcrossRegions(
|
||||
search: string,
|
||||
limit = 25,
|
||||
) {
|
||||
const trimmedSearch = search.trim();
|
||||
const normalizedLimit = Math.floor(limit / 3);
|
||||
|
||||
if (usernamePattern.test(trimmedSearch)) {
|
||||
return (
|
||||
await Promise.all([
|
||||
fetchBlitz<AccountList>('com', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'com' as Region,
|
||||
})),
|
||||
),
|
||||
fetchBlitz<AccountList>('eu', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'eu' as Region,
|
||||
})),
|
||||
),
|
||||
fetchBlitz<AccountList>('asia', 'account/list', {
|
||||
search,
|
||||
limit: normalizedLimit,
|
||||
}).then(
|
||||
(value) =>
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
region: 'asia' as Region,
|
||||
})),
|
||||
),
|
||||
])
|
||||
)
|
||||
.filter(Boolean)
|
||||
.flat() as AccountListWithServer;
|
||||
} else {
|
||||
return [] as AccountListWithServer;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { I_HAT } from '@blitzkit/core/src/math/axis';
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function unrotateDavaVector(vector: Vector3) {
|
||||
|
||||
Reference in new issue
Block a user