mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: removed non-proxy apis
This commit is contained in:
1 parent
925ac96264
commit
6ff2a23ff7
11 files changed
+54
-65
No files matched your search
@@ -7,7 +7,6 @@ package-lock.json
|
||||
dist/
|
||||
dist.*
|
||||
yarn-error.log
|
||||
commands.txt
|
||||
/test.*
|
||||
test.*
|
||||
/docs/.vitepress/dist
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import listPlayers from '../../../../core/blitz/listPlayers';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const search = request.nextUrl.searchParams.get('search');
|
||||
const limitParam = request.nextUrl.searchParams.get('limit');
|
||||
const limit = limitParam ? parseInt(limitParam) : undefined;
|
||||
const players = search ? await listPlayers(search, limit) : [];
|
||||
|
||||
return NextResponse.json(players);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { Region } from '../../../../../constants/regions';
|
||||
import getTankStats from '../../../../../core/blitz/getTankStats';
|
||||
import { NormalizedTankStats } from '../../../../../types/tanksStats';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const region = request.nextUrl.searchParams.get('region') as Region;
|
||||
const id = parseInt(request.nextUrl.searchParams.get('id')!);
|
||||
const tankStats = await getTankStats(region, id);
|
||||
const normalized = tankStats.reduce<NormalizedTankStats>(
|
||||
(accumulator, tank) => ({ ...accumulator, [tank.tank_id]: tank }),
|
||||
{},
|
||||
);
|
||||
|
||||
return NextResponse.json(normalized);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { tankopedia } from '../../../core/blitz/tankopedia';
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await tankopedia);
|
||||
}
|
||||
@@ -8,16 +8,24 @@ import { Button } from '../../../components/Button';
|
||||
import PageWrapper from '../../../components/PageWrapper';
|
||||
import { SearchBar } from '../../../components/SearchBar';
|
||||
import { REGION_NAMES } from '../../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||
import { diffNormalizedTankStats } from '../../../core/blitz/diffNormalizedTankStats';
|
||||
import { AccountListWithServer } from '../../../core/blitz/listPlayers';
|
||||
import getWargamingResponse from '../../../core/blitz/getWargamingResponse';
|
||||
import listPlayers, {
|
||||
AccountListWithServer,
|
||||
} from '../../../core/blitz/listPlayers';
|
||||
import { tankopedia } from '../../../core/blitz/tankopedia';
|
||||
import { theme } from '../../../stitches.config';
|
||||
import { useSession } from '../../../stores/session';
|
||||
import {
|
||||
IndividualTankStats,
|
||||
NormalizedTankStats,
|
||||
TanksStats,
|
||||
} from '../../../types/tanksStats';
|
||||
import * as styles from './page.css';
|
||||
|
||||
(async () => console.log(await tankopedia))();
|
||||
|
||||
export default function Page() {
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const [searchResults, setSearchResults] = useState<
|
||||
@@ -27,11 +35,7 @@ export default function Page() {
|
||||
const handleChange = debounce(
|
||||
async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
if (event.target.value) {
|
||||
const players = await fetch(
|
||||
`/api/search/players?search=${event.target.value}`,
|
||||
).then((response) => response.json() as Promise<AccountListWithServer>);
|
||||
|
||||
setSearchResults(players);
|
||||
setSearchResults(await listPlayers(event.target.value));
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
@@ -45,9 +49,18 @@ export default function Page() {
|
||||
(async () => {
|
||||
if (session.isTracking) {
|
||||
const { id, region } = session;
|
||||
const current = await fetch(
|
||||
`/api/stats/normalized/tanks?id=${id}®ion=${region}`,
|
||||
).then((response) => response.json() as Promise<NormalizedTankStats>);
|
||||
const currentRaw = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const current = currentRaw[id].reduce<
|
||||
Record<number, IndividualTankStats>
|
||||
>(
|
||||
(accumulator, curr) => ({
|
||||
...accumulator,
|
||||
[curr.tank_id]: curr,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
setDiff(diffNormalizedTankStats(session.tankStats, current));
|
||||
}
|
||||
@@ -197,7 +210,7 @@ export default function Page() {
|
||||
{diff &&
|
||||
(Object.entries(diff) as [string, IndividualTankStats][])
|
||||
.sort(([, a], [, b]) => b.last_battle_time - a.last_battle_time)
|
||||
.map(([id, tankStats]) => <Breakdown.Row key={id} />)}
|
||||
.map(([id, tankStats]) => <Breakdown.Row key={id} rows={[]} />)}
|
||||
</Breakdown.Root>
|
||||
</PageWrapper>
|
||||
);
|
||||
|
||||
@@ -24,8 +24,8 @@ export function BlitzkriegWormWide() {
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M68.399 14.8787C68.9756 14.8787 69.4874 14.7114 69.9346 14.3768C70.3876 14.0423 70.6141 13.47 70.6141 12.6601V11.9029C70.3611 12.261 70.0287 12.5515 69.6169 12.7745C69.205 12.9975 68.6608 13.1091 67.9842 13.1091C66.9369 13.1091 66.0956 12.7246 65.4601 11.9557C64.8306 11.181 64.5158 10.1773 64.5158 8.94479V8.66307C64.5158 7.43052 64.8188 6.42393 65.4248 5.64332C66.0367 4.85683 66.8898 4.46359 67.9842 4.46359C68.549 4.46359 69.0668 4.58098 69.5374 4.81575C70.0081 5.05052 70.3582 5.34692 70.5876 5.70495H70.6141L70.6318 4.63967H73.5V12.2023C73.5 13.7165 73.0852 14.8728 72.2556 15.671C71.4261 16.4751 70.3082 16.8771 68.902 16.8771H0V14.8787H68.399ZM67.8342 10.5207C67.5694 10.1157 67.437 9.59042 67.437 8.94479V8.67187C67.437 8.03212 67.5694 7.50682 67.8342 7.09597C68.0989 6.68512 68.5078 6.47969 69.0609 6.47969C69.4374 6.47969 69.7551 6.58534 70.014 6.79663C70.2788 7.00793 70.47 7.26031 70.5876 7.55377V10.0541C70.4759 10.3299 70.2876 10.5765 70.0228 10.7936C69.7581 11.0108 69.4404 11.1194 69.0697 11.1194C68.5108 11.1194 68.0989 10.9198 67.8342 10.5207Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { REGION_NAMES, Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { TankStats } from '../../types/tanksStats';
|
||||
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<TankStats>(
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
|
||||
|
||||
@@ -22,8 +22,12 @@ export interface Tankopedia {
|
||||
}
|
||||
|
||||
console.log('Caching tankopedia...');
|
||||
export const tankopedia = fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||
.then((response) => response.json())
|
||||
export const tankopedia = fetch(
|
||||
typeof window === 'undefined'
|
||||
? 'https://www.blitzstars.com/bs-tankopedia.json'
|
||||
: '/api/tankopedia',
|
||||
)
|
||||
.then(async (response) => response.json())
|
||||
.then((wrapperTankopedia) => {
|
||||
console.log('Tankopedia cached');
|
||||
return (wrapperTankopedia as { data: Tankopedia }).data;
|
||||
|
||||
@@ -131,22 +131,6 @@ export default async function today(
|
||||
const tankopediaEntry = (await tankopedia)[id];
|
||||
|
||||
return (
|
||||
// <Breakdown.Row
|
||||
// isTank={!showTotal || id !== 0}
|
||||
// tankType={tankopediaEntry?.type}
|
||||
// treeType={tankopediaEntry ? await getTreeType(id) : undefined}
|
||||
// minimized={showTotal ? index > maximized : index + 1 > maximized}
|
||||
// key={id}
|
||||
// name={showTotal && id === 0 ? 'Total' : await resolveTankName(id)}
|
||||
// winrate={tankStats.wins / tankStats.battles}
|
||||
// careerWinrate={career.wins / career.battles}
|
||||
// WN8={isNaN(todayWN8s[id]) ? undefined : todayWN8s[id]}
|
||||
// careerWN8={isNaN(careerWN8s[id]) ? undefined : careerWN8s[id]}
|
||||
// damage={tankStats.damage_dealt / tankStats.battles}
|
||||
// careerDamage={career.damage_dealt / career.battles}
|
||||
// battles={tankStats.battles}
|
||||
// careerBattles={career.battles}
|
||||
// />
|
||||
<Breakdown.Row
|
||||
key={id}
|
||||
type={!showTotal || id !== 0 ? 'tank' : 'summary'}
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface IndividualTankStats {
|
||||
tank_id: number;
|
||||
}
|
||||
|
||||
export interface TankStats {
|
||||
export interface TanksStats {
|
||||
[accountId: number]: IndividualTankStats[];
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -9,8 +9,12 @@
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"resolveJsonModule": true,
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"jsx": "preserve",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"incremental": true,
|
||||
"isolatedModules": true,
|
||||
@@ -20,6 +24,12 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": ["src/**/*", ".next/types/**/*.ts", "dist/website/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"include": [
|
||||
"src/**/*",
|
||||
".next/types/**/*.ts",
|
||||
"dist/website/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user