This commit is contained in:
dahyeon committed 2026-04-26 01:37:12 -07:00
1 parent 2472f865ad
commit c82bf55fe9
3 files changed
+31 -9

No files matched your search

@@ -5,19 +5,26 @@ const DDRAGON_BASE = 'https://ddragon.leagueoflegends.com';
const DDRAGON_CDN = `${DDRAGON_BASE}/cdn`;
const DEFAULT_LOCALE = 'ko_KR';
const CACHE_TTL_SECONDS = 24 * 60 * 60;
const CACHE_VERSION = 'v2';
const FETCH_TIMEOUT_MS = 10_000;
export interface DdragonChampionEntry {
key: string;
name: string;
}
export interface DdragonManifest {
version: string;
cdn: string;
locale: string;
champions: Record<string, string>;
champions: Record<string, DdragonChampionEntry>;
fetchedAt: string;
}
interface ChampionDataEntry {
key: string;
id: string;
name: string;
}
interface ChampionDataResponse {
@@ -77,17 +84,20 @@ export class RiotDdragonService {
private async fetchChampionMap(
version: string,
locale: string,
): Promise<Record<string, string>> {
): Promise<Record<string, DdragonChampionEntry>> {
const url = `${DDRAGON_CDN}/${version}/data/${locale}/champion.json`;
const payload = await this.fetchJson<ChampionDataResponse>(url);
if (!payload || typeof payload !== 'object' || !payload.data) {
throw new Error(`ddragon champion.json response is malformed (${url}).`);
}
const map: Record<string, string> = {};
const map: Record<string, DdragonChampionEntry> = {};
for (const entry of Object.values(payload.data)) {
if (entry?.key && entry.id) {
map[entry.key] = entry.id;
map[entry.key] = {
key: entry.id,
name: typeof entry.name === 'string' ? entry.name : entry.id,
};
}
}
return map;
@@ -128,5 +138,5 @@ function normalizeLocale(locale: string): string {
}
function manifestCacheKey(locale: string): string {
return `ddragon:manifest:${locale}`;
return `ddragon:manifest:${CACHE_VERSION}:${locale}`;
}