mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: use corsproxy.io
This commit is contained in:
1 parent
81c2ca80bc
commit
6b6ee94d9b
8 files changed
+20
-34
No files matched your search
@@ -1,10 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server';
|
|
||||||
import { Region } from '../../../../constants/regions';
|
|
||||||
import getRatingsInfo from '../../../../core/blitz/getRatingsInfo';
|
|
||||||
|
|
||||||
export async function GET(
|
|
||||||
request: Request,
|
|
||||||
{ params }: { params: { region: Region } },
|
|
||||||
) {
|
|
||||||
return NextResponse.json(await getRatingsInfo(params.region));
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server';
|
|
||||||
import { tankAverages } from '../../../core/blitzstars/tankAverages';
|
|
||||||
|
|
||||||
export async function GET() {
|
|
||||||
return NextResponse.json(await tankAverages);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server';
|
|
||||||
import { tankopedia } from '../../../core/blitzstars/tankopedia';
|
|
||||||
|
|
||||||
export async function GET() {
|
|
||||||
return NextResponse.json(await tankopedia);
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ export default function Page() {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const [newRatingsInfo, newLatestArchivedSeasonNumber] = await Promise.all(
|
const [newRatingsInfo, newLatestArchivedSeasonNumber] = await Promise.all(
|
||||||
[getRatingsInfo(ratings.region), getLatestArchivedSeasonNumber()],
|
[getRatingsInfo(ratings.region), getLatestArchivedSeasonNumber()],
|
||||||
);
|
);
|
||||||
|
|
||||||
setRatingsInfo(newRatingsInfo);
|
setRatingsInfo(newRatingsInfo);
|
||||||
setLatestArchivedSeasonNumber(newLatestArchivedSeasonNumber);
|
setLatestArchivedSeasonNumber(newLatestArchivedSeasonNumber);
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { RatingsInfo } from '../../commands/ratings';
|
import { RatingsInfo } from '../../commands/ratings';
|
||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { context } from '../blitzkrieg/context';
|
import { context } from '../blitzkrieg/context';
|
||||||
|
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||||
|
|
||||||
export default async function getRatingsInfo(region: Region) {
|
export default async function getRatingsInfo(region: Region) {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
context === 'bot'
|
withCORSProxy(
|
||||||
? `https://${regionToRegionSubdomain(
|
context === 'bot'
|
||||||
region,
|
? `https://${regionToRegionSubdomain(
|
||||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`
|
region,
|
||||||
: `/api/ratings-info/${region}`,
|
)}.wotblitz.com/en/api/rating-leaderboards/season/`
|
||||||
|
: `/api/ratings/info/${region}`,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return (await response.json()) as Promise<RatingsInfo>;
|
return (await response.json()) as Promise<RatingsInfo>;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { context } from './context';
|
||||||
|
|
||||||
|
export function withCORSProxy(url: string) {
|
||||||
|
return context === 'website'
|
||||||
|
? `https://corsproxy.wotblitz.com/?${encodeURIComponent(url)}`
|
||||||
|
: url;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { AllStats } from '../blitz/getAccountInfo';
|
import { AllStats } from '../blitz/getAccountInfo';
|
||||||
import { context } from '../blitzkrieg/context';
|
import { context } from '../blitzkrieg/context';
|
||||||
|
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||||
import { tankopedia } from './tankopedia';
|
import { tankopedia } from './tankopedia';
|
||||||
|
|
||||||
export interface SpecialStats {
|
export interface SpecialStats {
|
||||||
@@ -85,9 +86,7 @@ tankopedia;
|
|||||||
export type TankAverages = Record<number, IndividualTankAverage>;
|
export type TankAverages = Record<number, IndividualTankAverage>;
|
||||||
|
|
||||||
export const tankAverages = fetch(
|
export const tankAverages = fetch(
|
||||||
context === 'bot'
|
withCORSProxy('https://www.blitzstars.com/api/tankaverages.json'),
|
||||||
? 'https://www.blitzstars.com/api/tankaverages.json'
|
|
||||||
: '/api/tank-averages',
|
|
||||||
)
|
)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { deburr } from 'lodash';
|
import { deburr } from 'lodash';
|
||||||
import { context } from '../blitzkrieg/context';
|
import { context } from '../blitzkrieg/context';
|
||||||
|
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||||
|
|
||||||
export interface TankopediaEntry {
|
export interface TankopediaEntry {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -18,9 +19,7 @@ export interface Tankopedia {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const tankopedia = fetch(
|
export const tankopedia = fetch(
|
||||||
context === 'bot'
|
withCORSProxy('https://www.blitzstars.com/bs-tankopedia.json'),
|
||||||
? 'https://www.blitzstars.com/bs-tankopedia.json'
|
|
||||||
: '/api/tankopedia',
|
|
||||||
)
|
)
|
||||||
.then(async (response) => response.json())
|
.then(async (response) => response.json())
|
||||||
.then((wrapperTankopedia) =>
|
.then((wrapperTankopedia) =>
|
||||||
|
|||||||
Reference in new issue
Block a user