mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: proxy APIs
This commit is contained in:
1 parent
7e4f195f94
commit
14bfc3018b
14 files changed
+130
-60
No files matched your search
@@ -1,15 +1,15 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export default async function getRatingsInfo(region: Region) {
|
||||
const response = await fetch(
|
||||
withCORSProxy(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
),
|
||||
context === 'website'
|
||||
? `/api/${region}/ratings/current/info`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
);
|
||||
|
||||
return (await response.json()) as Promise<RatingsInfo>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LeagueTop } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingsLeague(
|
||||
@@ -11,11 +11,11 @@ export async function getRatingsLeague(
|
||||
) {
|
||||
const fetcher = usePatientFetcher ? patientFetch : fetch;
|
||||
const response = await fetcher(
|
||||
withCORSProxy(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`,
|
||||
),
|
||||
context === 'website'
|
||||
? `/api/${region}/ratings/current/league/${league}`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`,
|
||||
);
|
||||
const json = (await response.json()) as LeagueTop;
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { RatingsNeighbors } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export async function getRatingsNeighbors(
|
||||
region: Region,
|
||||
id: number,
|
||||
count = 30,
|
||||
count: number,
|
||||
usePatientFetcher = false,
|
||||
) {
|
||||
const fetcher = usePatientFetcher ? patientFetch : fetch;
|
||||
const response = await fetcher(
|
||||
withCORSProxy(
|
||||
`https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`,
|
||||
),
|
||||
context === 'website'
|
||||
? `/api/${region}/ratings/current/neighbors/${id}/${count}`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`,
|
||||
);
|
||||
const json = (await response.json()) as RatingsNeighbors;
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
type CurrentRatingsPlayerSearch = 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 searchCurrentRatingsPlayers(
|
||||
region: Region,
|
||||
name: string,
|
||||
) {
|
||||
const encodedSearch = encodeURIComponent(name);
|
||||
const response = await fetch(
|
||||
context === 'website'
|
||||
? `/api/${region}/ratings/current/search/${encodedSearch}`
|
||||
: `https://${regionToRegionSubdomain(
|
||||
region,
|
||||
)}.wotblitz.com/en/api/rating-leaderboards/search/?prefix=${encodedSearch}`,
|
||||
);
|
||||
const accountList = (await response.json()) as CurrentRatingsPlayerSearch;
|
||||
|
||||
return accountList;
|
||||
}
|
||||
Reference in new issue
Block a user