feat: core chunk 3

This commit is contained in:
TrèsAbhi committed 2023-10-14 10:58:48 -05:00
1 parent 970ab9004e
commit 07e3660388
25 files changed
+57 -58

No files matched your search

-3
View File
@@ -1,3 +0,0 @@
export function getClanLogo(emblemId: number) {
return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png`
}
-13
View File
@@ -1,13 +0,0 @@
import { RatingsInfo } from '../../commands/ratings';
import { Region } from '../../constants/regions';
import regionToRegionSubdomain from './regionToRegionSubdomain';
export default async function getRatingsInfo(region: Region) {
const response = await fetch(
`https://${regionToRegionSubdomain(
region,
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
);
return (await response.json()) as Promise<RatingsInfo>;
}
-20
View File
@@ -1,20 +0,0 @@
import { REGION_NAMES, Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import { TanksStats } from '../../types/tanksStats';
import throwError from '../node/throwError';
import getWargamingResponse from './getWargamingResponse';
export default async function getTankStats(region: Region, id: number) {
const tankStats = await getWargamingResponse<TanksStats>(
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
);
if (tankStats[id] === null) {
throw throwError(
'No tank stats available',
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${REGION_NAMES[region]} server.`,
);
}
return tankStats[id];
}
-11
View File
@@ -1,11 +0,0 @@
import { TreeTypeEnum } from '../../components/Tanks';
import { tankopedia } from './tankopedia';
export default async function getTreeType(id: number) {
const entry = (await tankopedia)[id];
if (entry?.is_collectible) return TreeTypeEnum.Collector;
if (entry?.is_premium) return TreeTypeEnum.Premium;
return TreeTypeEnum.TechTree;
}
-28
View File
@@ -1,28 +0,0 @@
import throwError from '../node/throwError';
export type WargamingResponse<Data extends object> =
| {
status: 'error';
error: { field: string; message: string; code: 402; value: null };
}
| {
status: 'ok';
data: Data;
};
export default async function getWargamingResponse<Data extends object>(
url: string,
) {
const data = (await fetch(url).then((response) =>
response.json(),
)) as WargamingResponse<Data>;
if (data.status === 'ok') {
return data.data;
} else {
throw throwError(
`Wargaming response error status:"${data.status}"`,
`Message: "${data.error.message}"\nURL: "${url}"`,
);
}
}
+4 -4
View File
@@ -1,7 +1,7 @@
import fetchBlitz from '../../_core/blitz/fetchWargaming';
import { Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import { Clan, ClanList } from '../../types/clanList';
import getWargamingResponse from './getWargamingResponse';
export type ClanListWithRegion = (Clan & {
region: 'com' | 'eu' | 'asia';
@@ -14,7 +14,7 @@ export default async function listClans(search: string, limit = 9) {
return (
await Promise.all([
getWargamingResponse<ClanList>(
fetchBlitz<ClanList>(
`https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
@@ -24,7 +24,7 @@ export default async function listClans(search: string, limit = 9) {
region: 'com' as Region,
})),
),
getWargamingResponse<ClanList>(
fetchBlitz<ClanList>(
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
@@ -34,7 +34,7 @@ export default async function listClans(search: string, limit = 9) {
region: 'eu' as Region,
})),
),
getWargamingResponse<ClanList>(
fetchBlitz<ClanList>(
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
+4 -4
View File
@@ -1,6 +1,6 @@
import fetchBlitz from '../../_core/blitz/fetchWargaming';
import { Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import getWargamingResponse from './getWargamingResponse';
interface Account {
nickname: string;
@@ -22,7 +22,7 @@ export default async function listPlayers(search: string, limit = 9) {
if (usernamePattern.test(trimmedSearch)) {
return (
await Promise.all([
getWargamingResponse<AccountList>(
fetchBlitz<AccountList>(
`https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
@@ -32,7 +32,7 @@ export default async function listPlayers(search: string, limit = 9) {
region: 'com' as Region,
})),
),
getWargamingResponse<AccountList>(
fetchBlitz<AccountList>(
`https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
@@ -42,7 +42,7 @@ export default async function listPlayers(search: string, limit = 9) {
region: 'eu' as Region,
})),
),
getWargamingResponse<AccountList>(
fetchBlitz<AccountList>(
`https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
+4 -4
View File
@@ -1,8 +1,8 @@
import { deburr } from 'lodash';
import fetchBlitz from '../../_core/blitz/fetchWargaming';
import { TreeTypeString } from '../../components/Tanks';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import { context } from '../blitzkrieg/context';
import getWargamingResponse from './getWargamingResponse';
import { TreeTypeString } from '../../components/Tanks';
export interface TankopediaEntry {
name: string;
@@ -16,7 +16,7 @@ export interface TankopediaEntry {
type: string;
description: string;
}
type asd = TreeTypeString
type asd = TreeTypeString;
export interface Tankopedia {
[id: number]: TankopediaEntry | undefined;
}
@@ -71,7 +71,7 @@ export interface TankopediaInfo {
// this is blocking because info is needed for command creation
console.log('Caching tankopedia info...');
export const tankopediaInfo = getWargamingResponse<TankopediaInfo>(
export const tankopediaInfo = fetchBlitz<TankopediaInfo>(
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${WARGAMING_APPLICATION_ID}`,
);
console.log('Cached tankopedia info');
+1 -1
View File
@@ -1,3 +1,4 @@
import getTankStats from '../../_core/blitz/getTankStats';
import { Region } from '../../constants/regions';
import {
GetHistoriesOptions,
@@ -5,7 +6,6 @@ import {
History,
getHistoriesDefaultOptions,
} from '../../types/histories';
import getTankStats from '../blitz/getTankStats';
import { emptyAllStats } from './getDiffedTankStats';
export interface TankHistory extends History {