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

27 lines
870 B
TypeScript
Raw Normal View History

import { RatingNeighbors } from '../../commands/ratingLeaderboard';
2023-11-07 20:47:20 -06:00
import { Region } from '../../constants/regions';
2024-04-20 12:00:48 -05:00
import { patientFetch } from '../blitzrinth/patientFetch';
import { withCORSProxy } from '../blitzrinth/withCORSProxy';
2023-11-07 20:47:20 -06:00
import regionToRegionSubdomain from './regionToRegionSubdomain';
export async function getRatingNeighbors(
2023-11-07 20:47:20 -06:00
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 RatingNeighbors;
2023-11-07 20:47:20 -06:00
return json;
}