.
This commit is contained in:
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}`;
|
||||
}
|
||||
@@ -221,10 +221,15 @@ export interface MatchesResponse {
|
||||
matches: ApiMatch[];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -14,7 +14,11 @@ import {
|
||||
useDevCaptainSide,
|
||||
} from '../config';
|
||||
import { ApiError } from '../lib/api';
|
||||
import { championIconUrl, profileIconUrl } from '../lib/ddragon';
|
||||
import {
|
||||
championDisplayName,
|
||||
championIconUrl,
|
||||
profileIconUrl,
|
||||
} from '../lib/ddragon';
|
||||
import { positionIcon, positionLabel } from '../lib/league';
|
||||
import type { Position } from '../api/types';
|
||||
|
||||
@@ -195,13 +199,16 @@ function PlayerSpotlight({
|
||||
{player.masteries.length > 0 ? (
|
||||
player.masteries.map((mastery) => {
|
||||
const iconUrl = championIconUrl(ddragon, mastery.championId);
|
||||
const displayName =
|
||||
championDisplayName(ddragon, mastery.championId) ??
|
||||
mastery.championName;
|
||||
return (
|
||||
<div key={mastery.championId} className="flex items-center gap-2">
|
||||
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
||||
{iconUrl ? (
|
||||
<img
|
||||
src={iconUrl}
|
||||
alt={mastery.championName}
|
||||
alt={displayName}
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
@@ -209,7 +216,7 @@ function PlayerSpotlight({
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-[12px] font-medium text-base-content truncate">
|
||||
{mastery.championName}
|
||||
{displayName}
|
||||
</div>
|
||||
<div className="text-[10px] text-base-content/25">
|
||||
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
|
||||
|
||||
Reference in new issue
Block a user