fix: spectator v5 + new gamename

This commit is contained in:
Valentin Kaelin 2024-04-14 20:57:27 +02:00
parent 346273ef2d
commit ed9dd523ba
No known key found for this signature in database
GPG key ID: B389A4E3DFF8E414
7 changed files with 32 additions and 20 deletions

View file

@ -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',

View file

@ -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)

View file

@ -60,11 +60,11 @@ export default class SpectatorEndpoint {
this.limiter = limiter
}
public summonerID(summonerID: string, region: string): Promise<CurrentGameInfoDTO | undefined> {
public puuid(puuid: string, region: string): Promise<CurrentGameInfoDTO | undefined> {
return new JaxRequest(
region,
this.config,
`spectator/v4/active-games/by-summoner/${summonerID}`,
`spectator/v5/active-games/by-summoner/${puuid}`,
this.limiter,
0
).execute()

View file

@ -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

View file

@ -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')
) {

View file

@ -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<SummonerDTO | null> {
const name = summonerName.toLowerCase()
public async getSummoner(
summonerName: string,
region: string
): Promise<SummonerDTOExtended | null> {
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
}

View file

@ -24,7 +24,7 @@ export default class SummonerLiveValidator {
* ```
*/
public schema = schema.create({
id: schema.string(),
puuid: schema.string(),
region: schema.string(),
})