.
This commit is contained in:
1 parent
5af2c80cd1
commit
f7ee34da4f
78 files changed
+9016
-150
No files matched your search
@@ -2,18 +2,39 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||
import { SecretService } from '../global/secret/secret.service';
|
||||
import {
|
||||
RiotApiErrorBody,
|
||||
RiotPlatformRoute,
|
||||
RiotRegionalRoute,
|
||||
RiotRequestOptions,
|
||||
RiotResponseParser,
|
||||
} from './riot.types';
|
||||
|
||||
const RIOT_BASE_URLS: Record<RiotRegionalRoute, string> = {
|
||||
const RIOT_REGION_BASE_URLS: Record<RiotRegionalRoute, string> = {
|
||||
americas: 'https://americas.api.riotgames.com',
|
||||
asia: 'https://asia.api.riotgames.com',
|
||||
europe: 'https://europe.api.riotgames.com',
|
||||
sea: 'https://sea.api.riotgames.com',
|
||||
};
|
||||
|
||||
const RIOT_PLATFORM_BASE_URLS: Record<RiotPlatformRoute, string> = {
|
||||
br1: 'https://br1.api.riotgames.com',
|
||||
eun1: 'https://eun1.api.riotgames.com',
|
||||
euw1: 'https://euw1.api.riotgames.com',
|
||||
jp1: 'https://jp1.api.riotgames.com',
|
||||
kr: 'https://kr.api.riotgames.com',
|
||||
la1: 'https://la1.api.riotgames.com',
|
||||
la2: 'https://la2.api.riotgames.com',
|
||||
me1: 'https://me1.api.riotgames.com',
|
||||
na1: 'https://na1.api.riotgames.com',
|
||||
oc1: 'https://oc1.api.riotgames.com',
|
||||
ph2: 'https://ph2.api.riotgames.com',
|
||||
ru: 'https://ru.api.riotgames.com',
|
||||
sg2: 'https://sg2.api.riotgames.com',
|
||||
th2: 'https://th2.api.riotgames.com',
|
||||
tr1: 'https://tr1.api.riotgames.com',
|
||||
tw2: 'https://tw2.api.riotgames.com',
|
||||
vn2: 'https://vn2.api.riotgames.com',
|
||||
};
|
||||
|
||||
export class RiotApiError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
@@ -67,8 +88,9 @@ export class RiotClientService {
|
||||
}
|
||||
|
||||
private buildUrl(path: string, options: RiotRequestOptions): string {
|
||||
const region = options.region ?? 'asia';
|
||||
const baseUrl = RIOT_BASE_URLS[region];
|
||||
const baseUrl = options.platform
|
||||
? RIOT_PLATFORM_BASE_URLS[options.platform]
|
||||
: RIOT_REGION_BASE_URLS[options.region ?? 'asia'];
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
||||
const url = new URL(`${baseUrl}${normalizedPath}`);
|
||||
|
||||
|
||||
Reference in new issue
Block a user