.
This commit is contained in:
1 parent
86d6767eba
commit
09286e7711
7 files changed
+639
-56
No files matched your search
@@ -883,10 +883,24 @@ export class CommunityStatsService {
|
||||
gameName: participant.summonerName,
|
||||
tagLine: '',
|
||||
championId: participant.championId,
|
||||
championLevel: participant.championLevel,
|
||||
teamPosition: participant.teamPosition,
|
||||
kills: participant.kills,
|
||||
deaths: participant.deaths,
|
||||
assists: participant.assists,
|
||||
items: participant.items,
|
||||
trinket: participant.trinket,
|
||||
summonerSpells: participant.summonerSpells,
|
||||
perks: participant.perks,
|
||||
totalCs: participant.cs,
|
||||
csPerMin: participant.csPerMin,
|
||||
goldEarned: participant.gold,
|
||||
damageDealtToChampions: participant.damageDealtToChampions,
|
||||
damageTaken: participant.damageTaken,
|
||||
visionScore: participant.visionScore,
|
||||
wardsPlaced: participant.wardsPlaced,
|
||||
wardsKilled: participant.wardsKilled,
|
||||
controlWardsBought: participant.controlWardsBought,
|
||||
})),
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -579,16 +579,45 @@ export class MatchHistoryService {
|
||||
},
|
||||
participants: match.info.participants
|
||||
.filter((participant) => participant.teamId === team.teamId)
|
||||
.map((participant) => ({
|
||||
puuid: participant.puuid,
|
||||
gameName: participant.riotIdGameName || participant.summonerName || 'Unknown',
|
||||
tagLine: participant.riotIdTagLine || '',
|
||||
championId: participant.championId,
|
||||
teamPosition: participant.teamPosition || participant.individualPosition,
|
||||
kills: participant.kills,
|
||||
deaths: participant.deaths,
|
||||
assists: participant.assists,
|
||||
})),
|
||||
.map((participant) => {
|
||||
const totalCs = this.resolveTotalCs(participant);
|
||||
const minutes = this.resolveGameMinutes(match, participant);
|
||||
|
||||
return {
|
||||
puuid: participant.puuid,
|
||||
gameName: participant.riotIdGameName || participant.summonerName || 'Unknown',
|
||||
tagLine: participant.riotIdTagLine || '',
|
||||
championId: participant.championId,
|
||||
championLevel: participant.champLevel,
|
||||
teamPosition: participant.teamPosition || participant.individualPosition,
|
||||
kills: participant.kills,
|
||||
deaths: participant.deaths,
|
||||
assists: participant.assists,
|
||||
items: [
|
||||
participant.item0,
|
||||
participant.item1,
|
||||
participant.item2,
|
||||
participant.item3,
|
||||
participant.item4,
|
||||
participant.item5,
|
||||
],
|
||||
trinket: participant.item6,
|
||||
summonerSpells: [participant.summoner1Id, participant.summoner2Id],
|
||||
perks: this.resolvePerks(participant),
|
||||
totalCs,
|
||||
csPerMin: this.average(totalCs, minutes),
|
||||
goldEarned: participant.goldEarned,
|
||||
damageDealtToChampions: participant.totalDamageDealtToChampions,
|
||||
damageTaken: participant.totalDamageTaken,
|
||||
visionScore: participant.visionScore,
|
||||
wardsPlaced: participant.wardsPlaced,
|
||||
wardsKilled: participant.wardsKilled,
|
||||
controlWardsBought: this.numberField(
|
||||
participant,
|
||||
'visionWardsBoughtInGame',
|
||||
),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,31 @@ export interface RecentMatchesResponse {
|
||||
season: HistorySeasonDto;
|
||||
}
|
||||
|
||||
export interface RecentMatchTeamParticipantView {
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
championId: number;
|
||||
championLevel: number;
|
||||
teamPosition: string;
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
items: number[];
|
||||
trinket: number;
|
||||
summonerSpells: [number, number];
|
||||
perks: { primaryStyle?: number; subStyle?: number; keystone?: number };
|
||||
totalCs: number;
|
||||
csPerMin: number;
|
||||
goldEarned: number;
|
||||
damageDealtToChampions: number;
|
||||
damageTaken: number;
|
||||
visionScore: number;
|
||||
wardsPlaced: number;
|
||||
wardsKilled: number;
|
||||
controlWardsBought: number;
|
||||
}
|
||||
|
||||
export interface RecentMatchView {
|
||||
matchId: string;
|
||||
queueId: number;
|
||||
@@ -132,15 +157,6 @@ export interface RecentMatchView {
|
||||
side: 100 | 200;
|
||||
win: boolean;
|
||||
objectives?: { baron?: number; dragon?: number; tower?: number };
|
||||
participants: Array<{
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
championId: number;
|
||||
teamPosition: string;
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
}>;
|
||||
participants: RecentMatchTeamParticipantView[];
|
||||
}>;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ 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 CACHE_VERSION = 'v3';
|
||||
const FETCH_TIMEOUT_MS = 10_000;
|
||||
|
||||
export interface DdragonChampionEntry {
|
||||
@@ -13,11 +13,29 @@ export interface DdragonChampionEntry {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface DdragonSummonerSpellEntry {
|
||||
key: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface DdragonRuneEntry {
|
||||
id: number;
|
||||
key: string;
|
||||
icon: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface DdragonRuneStyleEntry extends DdragonRuneEntry {
|
||||
slots: Array<{ runes: DdragonRuneEntry[] }>;
|
||||
}
|
||||
|
||||
export interface DdragonManifest {
|
||||
version: string;
|
||||
cdn: string;
|
||||
locale: string;
|
||||
champions: Record<string, DdragonChampionEntry>;
|
||||
summonerSpells: Record<string, DdragonSummonerSpellEntry>;
|
||||
runesReforged: DdragonRuneStyleEntry[];
|
||||
fetchedAt: string;
|
||||
}
|
||||
|
||||
@@ -31,6 +49,27 @@ interface ChampionDataResponse {
|
||||
data: Record<string, ChampionDataEntry>;
|
||||
}
|
||||
|
||||
interface SummonerSpellDataEntry {
|
||||
key: string;
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface SummonerSpellDataResponse {
|
||||
data: Record<string, SummonerSpellDataEntry>;
|
||||
}
|
||||
|
||||
interface RuneDataEntry {
|
||||
id: number;
|
||||
key: string;
|
||||
icon: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface RuneStyleDataEntry extends RuneDataEntry {
|
||||
slots?: Array<{ runes?: RuneDataEntry[] }>;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class RiotDdragonService {
|
||||
private readonly logger = new Logger(RiotDdragonService.name);
|
||||
@@ -63,12 +102,18 @@ export class RiotDdragonService {
|
||||
|
||||
private async buildManifest(locale: string): Promise<DdragonManifest> {
|
||||
const version = await this.fetchLatestVersion();
|
||||
const champions = await this.fetchChampionMap(version, locale);
|
||||
const [champions, summonerSpells, runesReforged] = await Promise.all([
|
||||
this.fetchChampionMap(version, locale),
|
||||
this.fetchSummonerSpellMap(version, locale),
|
||||
this.fetchRuneStyles(version, locale),
|
||||
]);
|
||||
return {
|
||||
version,
|
||||
cdn: DDRAGON_CDN,
|
||||
locale,
|
||||
champions,
|
||||
summonerSpells,
|
||||
runesReforged,
|
||||
fetchedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@@ -103,6 +148,58 @@ export class RiotDdragonService {
|
||||
return map;
|
||||
}
|
||||
|
||||
private async fetchSummonerSpellMap(
|
||||
version: string,
|
||||
locale: string,
|
||||
): Promise<Record<string, DdragonSummonerSpellEntry>> {
|
||||
const url = `${DDRAGON_CDN}/${version}/data/${locale}/summoner.json`;
|
||||
const payload = await this.fetchJson<SummonerSpellDataResponse>(url);
|
||||
if (!payload || typeof payload !== 'object' || !payload.data) {
|
||||
throw new Error(`ddragon summoner.json response is malformed (${url}).`);
|
||||
}
|
||||
|
||||
const map: Record<string, DdragonSummonerSpellEntry> = {};
|
||||
for (const entry of Object.values(payload.data)) {
|
||||
if (entry?.key && entry.id) {
|
||||
map[entry.key] = {
|
||||
key: entry.id,
|
||||
name: typeof entry.name === 'string' ? entry.name : entry.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private async fetchRuneStyles(
|
||||
version: string,
|
||||
locale: string,
|
||||
): Promise<DdragonRuneStyleEntry[]> {
|
||||
const url = `${DDRAGON_CDN}/${version}/data/${locale}/runesReforged.json`;
|
||||
const payload = await this.fetchJson<unknown>(url);
|
||||
if (!Array.isArray(payload)) {
|
||||
throw new Error(`ddragon runesReforged.json response is malformed (${url}).`);
|
||||
}
|
||||
|
||||
return payload
|
||||
.filter((style): style is RuneStyleDataEntry => isRuneEntry(style))
|
||||
.map((style) => ({
|
||||
id: style.id,
|
||||
key: style.key,
|
||||
icon: style.icon,
|
||||
name: style.name,
|
||||
slots: (style.slots ?? []).map((slot) => ({
|
||||
runes: (slot.runes ?? [])
|
||||
.filter((rune): rune is RuneDataEntry => isRuneEntry(rune))
|
||||
.map((rune) => ({
|
||||
id: rune.id,
|
||||
key: rune.key,
|
||||
icon: rune.icon,
|
||||
name: rune.name,
|
||||
})),
|
||||
})),
|
||||
}));
|
||||
}
|
||||
|
||||
private async fetchJson<T>(url: string): Promise<T> {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
||||
@@ -137,6 +234,17 @@ function normalizeLocale(locale: string): string {
|
||||
return `${trimmed.slice(0, 2).toLowerCase()}_${trimmed.slice(3).toUpperCase()}`;
|
||||
}
|
||||
|
||||
function isRuneEntry(value: unknown): value is RuneDataEntry {
|
||||
if (!value || typeof value !== 'object') return false;
|
||||
const entry = value as Partial<RuneDataEntry>;
|
||||
return (
|
||||
typeof entry.id === 'number' &&
|
||||
typeof entry.key === 'string' &&
|
||||
typeof entry.icon === 'string' &&
|
||||
typeof entry.name === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
function manifestCacheKey(locale: string): string {
|
||||
return `ddragon:manifest:${CACHE_VERSION}:${locale}`;
|
||||
}
|
||||
Reference in new issue
Block a user