From ed9dd523ba51a2e12657b376de858001d4d06e45 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sun, 14 Apr 2024 20:57:27 +0200 Subject: [PATCH] fix: spectator v5 + new gamename --- client/src/store/modules/summoner.js | 2 +- .../Controllers/Http/SummonersController.ts | 6 ++-- .../Jax/src/Endpoints/SpectatorEndpoint.ts | 4 +-- .../Jax/src/Endpoints/SummonerEndpoint.ts | 5 ++- server/app/Services/Jax/src/JaxRequest.ts | 2 +- server/app/Services/SummonerService.ts | 31 ++++++++++++------- .../app/Validators/SummonerLiveValidator.ts | 2 +- 7 files changed, 32 insertions(+), 20 deletions(-) diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 0c05158..2c3194c 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -191,7 +191,7 @@ export const actions = { const resp = await axios({ url: 'summoner/live', data: { - id: state.basic.account.id, + puuid: state.basic.account.puuid, region: rootState.regionsList[rootState.settings.region], }, method: 'POST', diff --git a/server/app/Controllers/Http/SummonersController.ts b/server/app/Controllers/Http/SummonersController.ts index 0d65c70..d377aba 100644 --- a/server/app/Controllers/Http/SummonersController.ts +++ b/server/app/Controllers/Http/SummonersController.ts @@ -48,7 +48,7 @@ export default class SummonersController { SummonerService.getAllSummonerNames(account, summonerDB), this.getSeasons(account.puuid), MatchRepository.gamemodes(account.puuid), - Jax.Spectator.summonerID(account.id, region), + Jax.Spectator.puuid(account.puuid, region), SummonerService.getRanked(account.id, region), MatchRepository.recentActivity(account.puuid), // Only last 100 matchIds in matchlist @@ -146,10 +146,10 @@ export default class SummonersController { */ public async liveMatchDetails({ request, response }: HttpContextContract) { console.time('liveMatchDetails') - const { id, region } = await request.validate(SummonerLiveValidator) + const { puuid, region } = await request.validate(SummonerLiveValidator) // CURRENT GAME - const currentGame = await Jax.Spectator.summonerID(id, region) + const currentGame = await Jax.Spectator.puuid(puuid, region) if (!currentGame) { return response.json(null) diff --git a/server/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts b/server/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts index 5307aa6..700ef8f 100644 --- a/server/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts +++ b/server/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts @@ -60,11 +60,11 @@ export default class SpectatorEndpoint { this.limiter = limiter } - public summonerID(summonerID: string, region: string): Promise { + public puuid(puuid: string, region: string): Promise { return new JaxRequest( region, this.config, - `spectator/v4/active-games/by-summoner/${summonerID}`, + `spectator/v5/active-games/by-summoner/${puuid}`, this.limiter, 0 ).execute() diff --git a/server/app/Services/Jax/src/Endpoints/SummonerEndpoint.ts b/server/app/Services/Jax/src/Endpoints/SummonerEndpoint.ts index a3400bf..e805121 100644 --- a/server/app/Services/Jax/src/Endpoints/SummonerEndpoint.ts +++ b/server/app/Services/Jax/src/Endpoints/SummonerEndpoint.ts @@ -6,12 +6,15 @@ export interface SummonerDTO { accountId: string profileIconId: number revisionDate: number - name: string id: string puuid: string summonerLevel: number } +export interface SummonerDTOExtended extends SummonerDTO { + name: string +} + export default class SummonerEndpoint { private config: JaxConfig private limiter: RiotRateLimiter diff --git a/server/app/Services/Jax/src/JaxRequest.ts b/server/app/Services/Jax/src/JaxRequest.ts index 6c40f61..63108e8 100644 --- a/server/app/Services/Jax/src/JaxRequest.ts +++ b/server/app/Services/Jax/src/JaxRequest.ts @@ -69,7 +69,7 @@ export default class JaxRequest { // Don't log 404 when summoner isn't playing or the summoner doesn't exist // Or if summoner has no MatchList if ( - !this.endpoint.includes('spectator/v4/active-games/by-summoner') && + !this.endpoint.includes('spectator/v5/active-games/by-summoner') && !this.endpoint.includes('summoner/v4/summoners/by-name') && !this.endpoint.includes('match/v4/matchlists/by-account') ) { diff --git a/server/app/Services/SummonerService.ts b/server/app/Services/SummonerService.ts index 93935ee..228be33 100644 --- a/server/app/Services/SummonerService.ts +++ b/server/app/Services/SummonerService.ts @@ -1,5 +1,5 @@ import Jax from './Jax' -import { SummonerDTO } from 'App/Services/Jax/src/Endpoints/SummonerEndpoint' +import { SummonerDTO, SummonerDTOExtended } from 'App/Services/Jax/src/Endpoints/SummonerEndpoint' import { LeagueEntryDTO } from './Jax/src/Endpoints/LeagueEndpoint' import Summoner from 'App/Models/Summoner' import { PlayerRankParsed } from 'App/Parsers/ParsedType' @@ -33,7 +33,7 @@ class SummonerService { * Helper to transform League Data from the Riot API * @param league raw data of the league from Riot API */ - private getleagueData(league?: LeagueEntryDTO): LeagueEntryByQueue | null { + private getLeagueData(league?: LeagueEntryDTO): LeagueEntryByQueue | null { if (!league) { return null } @@ -54,22 +54,31 @@ class SummonerService { } /** - * Get summnoner account infos for a searched summoner name + * Get summoner account infos for a searched summoner name * @param summonerName * @param region */ - public async getSummoner(summonerName: string, region: string): Promise { - const name = summonerName.toLowerCase() + public async getSummoner( + summonerName: string, + region: string + ): Promise { + let name = summonerName.toLowerCase() - // Get old way: summonerName + // Get old way if (!name.includes(ACCOUNT_NAME_DELIMITER)) { - return Jax.Summoner.summonerName(name, region) + name = `${name}-${region}` } // Get new way: gameName#tagLine const [gameName, tagLine] = name.split(ACCOUNT_NAME_DELIMITER) const account = await Jax.Account.byRiotId(gameName, tagLine, region) - return account ? Jax.Summoner.summonerPuuid(account.puuid, region) : null + + if (account) { + const summoner = await Jax.Summoner.summonerPuuid(account.puuid, region) + return { ...summoner, name: account.gameName } + } + + return null } /** @@ -77,7 +86,7 @@ class SummonerService { * @param account of the summoner * @param summonerDB summoner in the database */ - public async getAllSummonerNames(account: SummonerDTO, summonerDB: Summoner) { + public async getAllSummonerNames(account: SummonerDTOExtended, summonerDB: Summoner) { await summonerDB.related('names').firstOrCreate({ name: account.name, }) @@ -95,9 +104,9 @@ class SummonerService { if (ranked && ranked.length) { result.soloQ = - this.getleagueData(ranked.find((e) => e.queueType === 'RANKED_SOLO_5x5')) || undefined + this.getLeagueData(ranked.find((e) => e.queueType === 'RANKED_SOLO_5x5')) || undefined result.flex5v5 = - this.getleagueData(ranked.find((e) => e.queueType === 'RANKED_FLEX_SR')) || undefined + this.getLeagueData(ranked.find((e) => e.queueType === 'RANKED_FLEX_SR')) || undefined } return result } diff --git a/server/app/Validators/SummonerLiveValidator.ts b/server/app/Validators/SummonerLiveValidator.ts index 4545102..6b70aca 100644 --- a/server/app/Validators/SummonerLiveValidator.ts +++ b/server/app/Validators/SummonerLiveValidator.ts @@ -24,7 +24,7 @@ export default class SummonerLiveValidator { * ``` */ public schema = schema.create({ - id: schema.string(), + puuid: schema.string(), region: schema.string(), })