Files
blitzkit/src/core/blitz/getRatingsNeighbors.ts
T

27 lines
863 B
TypeScript
Raw Normal View History

2023-11-07 20:47:20 -06:00
import { RatingsNeighbors } from '../../commands/ratings';
import { Region } from '../../constants/regions';
import { patientFetch } from '../blitzkrieg/patientFetch';
2023-11-13 21:52:21 -06:00
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
2023-11-07 20:47:20 -06:00
import regionToRegionSubdomain from './regionToRegionSubdomain';
export async function getRatingsNeighbors(
region: Region,
id: number,
2023-11-11 21:37:59 -06:00
count: number,
2023-11-07 20:47:20 -06:00
usePatientFetcher = false,
) {
const fetcher = (url: string) =>
usePatientFetcher
? patientFetch(url, undefined, { cache: 'no-store' })
: fetch(url, { cache: 'no-store' });
2023-11-07 20:47:20 -06:00
const response = await fetcher(
2023-11-13 21:52:21 -06:00
withCORSProxy(
`https://${regionToRegionSubdomain(
region,
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`,
),
2023-11-07 20:47:20 -06:00
);
const json = (await response.json()) as RatingsNeighbors;
return json;
}