.
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 DDRAGON_CDN = `${DDRAGON_BASE}/cdn`;
|
||||||
const DEFAULT_LOCALE = 'ko_KR';
|
const DEFAULT_LOCALE = 'ko_KR';
|
||||||
const CACHE_TTL_SECONDS = 24 * 60 * 60;
|
const CACHE_TTL_SECONDS = 24 * 60 * 60;
|
||||||
|
const CACHE_VERSION = 'v2';
|
||||||
const FETCH_TIMEOUT_MS = 10_000;
|
const FETCH_TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
|
export interface DdragonChampionEntry {
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DdragonManifest {
|
export interface DdragonManifest {
|
||||||
version: string;
|
version: string;
|
||||||
cdn: string;
|
cdn: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
champions: Record<string, string>;
|
champions: Record<string, DdragonChampionEntry>;
|
||||||
fetchedAt: string;
|
fetchedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChampionDataEntry {
|
interface ChampionDataEntry {
|
||||||
key: string;
|
key: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChampionDataResponse {
|
interface ChampionDataResponse {
|
||||||
@@ -77,17 +84,20 @@ export class RiotDdragonService {
|
|||||||
private async fetchChampionMap(
|
private async fetchChampionMap(
|
||||||
version: string,
|
version: string,
|
||||||
locale: string,
|
locale: string,
|
||||||
): Promise<Record<string, string>> {
|
): Promise<Record<string, DdragonChampionEntry>> {
|
||||||
const url = `${DDRAGON_CDN}/${version}/data/${locale}/champion.json`;
|
const url = `${DDRAGON_CDN}/${version}/data/${locale}/champion.json`;
|
||||||
const payload = await this.fetchJson<ChampionDataResponse>(url);
|
const payload = await this.fetchJson<ChampionDataResponse>(url);
|
||||||
if (!payload || typeof payload !== 'object' || !payload.data) {
|
if (!payload || typeof payload !== 'object' || !payload.data) {
|
||||||
throw new Error(`ddragon champion.json response is malformed (${url}).`);
|
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)) {
|
for (const entry of Object.values(payload.data)) {
|
||||||
if (entry?.key && entry.id) {
|
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;
|
return map;
|
||||||
@@ -128,5 +138,5 @@ function normalizeLocale(locale: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function manifestCacheKey(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[];
|
matches: ApiMatch[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DdragonChampionEntry {
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DdragonManifest {
|
export interface DdragonManifest {
|
||||||
version: string;
|
version: string;
|
||||||
cdn: string;
|
cdn: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
champions: Record<string, string>;
|
champions: Record<string, DdragonChampionEntry>;
|
||||||
fetchedAt: string;
|
fetchedAt: string;
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,11 @@ import {
|
|||||||
useDevCaptainSide,
|
useDevCaptainSide,
|
||||||
} from '../config';
|
} from '../config';
|
||||||
import { ApiError } from '../lib/api';
|
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 { positionIcon, positionLabel } from '../lib/league';
|
||||||
import type { Position } from '../api/types';
|
import type { Position } from '../api/types';
|
||||||
|
|
||||||
@@ -195,13 +199,16 @@ function PlayerSpotlight({
|
|||||||
{player.masteries.length > 0 ? (
|
{player.masteries.length > 0 ? (
|
||||||
player.masteries.map((mastery) => {
|
player.masteries.map((mastery) => {
|
||||||
const iconUrl = championIconUrl(ddragon, mastery.championId);
|
const iconUrl = championIconUrl(ddragon, mastery.championId);
|
||||||
|
const displayName =
|
||||||
|
championDisplayName(ddragon, mastery.championId) ??
|
||||||
|
mastery.championName;
|
||||||
return (
|
return (
|
||||||
<div key={mastery.championId} className="flex items-center gap-2">
|
<div key={mastery.championId} className="flex items-center gap-2">
|
||||||
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
||||||
{iconUrl ? (
|
{iconUrl ? (
|
||||||
<img
|
<img
|
||||||
src={iconUrl}
|
src={iconUrl}
|
||||||
alt={mastery.championName}
|
alt={displayName}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
@@ -209,7 +216,7 @@ function PlayerSpotlight({
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="text-[12px] font-medium text-base-content truncate">
|
<div className="text-[12px] font-medium text-base-content truncate">
|
||||||
{mastery.championName}
|
{displayName}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-[10px] text-base-content/25">
|
<div className="text-[10px] text-base-content/25">
|
||||||
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
|
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
|
||||||
|
|||||||
Reference in new issue
Block a user