refactor: quickly adapt merged PR

This commit is contained in:
Valentin Kaelin 2024-01-14 14:59:54 +01:00
parent ceac859907
commit 346273ef2d
9 changed files with 57 additions and 55 deletions

View file

@ -110,15 +110,15 @@ export default {
} }
}, },
$route(newRoute) { $route(newRoute) {
this.summoner = newRoute.params.name this.summoner = newRoute.params.name.replaceAll('-', '#')
this.dropdown = false this.dropdown = false
this.open = false this.open = false
}, },
}, },
created() { created() {
if (!this.summoner.length && !this.homepage) { if (!this.summoner.length && !this.homepage && this.$route.params.name) {
this.summoner = this.$route.params.name this.summoner = this.$route.params.name.replaceAll('-', '#')
} }
window.addEventListener('blur', this.windowBlur) window.addEventListener('blur', this.windowBlur)
window.addEventListener('keydown', this.handleEscape) window.addEventListener('keydown', this.handleEscape)
@ -148,7 +148,7 @@ export default {
document.body.style.overflow = 'hidden' document.body.style.overflow = 'hidden'
}, },
formSubmit() { formSubmit() {
const search = this.summoner.split(' ').join('').replace('+', ' ').replace('#', '-') const search = this.summoner.split(' ').join('').replaceAll('+', ' ').replaceAll('#', '-')
if (search.length) { if (search.length) {
this.$emit('formSubmit', search, this.selectedRegion) this.$emit('formSubmit', search, this.selectedRegion)
} }

View file

@ -35,31 +35,7 @@ export default class SummonersController {
const { summoner, region } = await request.validate(SummonerBasicValidator) const { summoner, region } = await request.validate(SummonerBasicValidator)
try { try {
// Coming from C++ this seems completely fine. Which suggests to me that it likely isn't. const account = await SummonerService.getSummoner(summoner, region)
var account
// Checks if searching for Riot tag. Frontend is currently replacing `#` with `-`.
if (!summoner.includes(`-`)) {
account = await SummonerService.getAccount(summoner, region)
} else {
const [name, tagline] = summoner.split(`-`)
account = await SummonerService.getRiotAccountByName(name, tagline, region)
if (!account) {
return response.json(null)
}
const additionalInfo = await SummonerService.getSummonerByPuuid(account.puuid, region)
if (!additionalInfo) {
return response.json(null)
}
account = {
...account,
...additionalInfo,
}
}
// Check if the summoner is found // Check if the summoner is found
if (!account) { if (!account) {
return response.json(null) return response.json(null)

View file

@ -0,0 +1,31 @@
import RiotRateLimiter from 'riot-ratelimiter'
import { JaxConfig } from '../../JaxConfig'
import JaxRequest from '../JaxRequest'
import { getRiotRegion } from 'App/helpers'
export interface AccountDto {
puuid: string
gameName: string
tagLine: string
}
export default class AccountEndpoint {
private config: JaxConfig
private limiter: RiotRateLimiter
constructor(config: JaxConfig, limiter: RiotRateLimiter) {
this.config = config
this.limiter = limiter
}
public byRiotId(name: string, tagline: string, region: string): Promise<AccountDto> {
return new JaxRequest(
getRiotRegion(region),
this.config,
`account/v1/accounts/by-riot-id/${name}/${tagline}`,
this.limiter,
36000,
'riot'
).execute()
}
}

View file

@ -1,8 +1,6 @@
// import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
import RiotRateLimiter from 'riot-ratelimiter' import RiotRateLimiter from 'riot-ratelimiter'
import { JaxConfig } from '../../JaxConfig' import { JaxConfig } from '../../JaxConfig'
import JaxRequest from '../JaxRequest' import JaxRequest from '../JaxRequest'
import { getRiotRegion } from 'App/helpers'
export interface SummonerDTO { export interface SummonerDTO {
accountId: string accountId: string
@ -53,17 +51,6 @@ export default class SummonerEndpoint {
).execute() ).execute()
} }
public puuidFromRiotTag(name: string, tagline: string, region: string): Promise<SummonerDTO> {
return new JaxRequest(
getRiotRegion(region),
this.config,
`account/v1/accounts/by-riot-id/${name}/${tagline}`,
this.limiter,
36000,
`riot`
).execute()
}
public summonerPuuid(puuid: string, region: string): Promise<SummonerDTO> { public summonerPuuid(puuid: string, region: string): Promise<SummonerDTO> {
return new JaxRequest( return new JaxRequest(
region, region,

View file

@ -1,3 +1,4 @@
import AccountEndpoint from './Endpoints/AccountEndpoint'
import LeagueEndpoint from './Endpoints/LeagueEndpoint' import LeagueEndpoint from './Endpoints/LeagueEndpoint'
import MatchEndpoint from './Endpoints/MatchEndpoint' import MatchEndpoint from './Endpoints/MatchEndpoint'
import MatchlistEndpoint from './Endpoints/MatchlistEndpoint' import MatchlistEndpoint from './Endpoints/MatchlistEndpoint'
@ -5,7 +6,6 @@ import SummonerEndpoint from './Endpoints/SummonerEndpoint'
import SpectatorEndpoint from './Endpoints/SpectatorEndpoint' import SpectatorEndpoint from './Endpoints/SpectatorEndpoint'
import CDragonEndpoint from './Endpoints/CDragonEndpoint' import CDragonEndpoint from './Endpoints/CDragonEndpoint'
import { JaxConfig } from '../JaxConfig' import { JaxConfig } from '../JaxConfig'
// import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
import RiotRateLimiter from 'riot-ratelimiter' import RiotRateLimiter from 'riot-ratelimiter'
import { STRATEGY } from 'riot-ratelimiter/dist/RateLimiter' import { STRATEGY } from 'riot-ratelimiter/dist/RateLimiter'
import MatchV4Endpoint from './Endpoints/MatchV4Endpoint' import MatchV4Endpoint from './Endpoints/MatchV4Endpoint'
@ -15,6 +15,7 @@ export default class Jax {
public key: string public key: string
public limiter: RiotRateLimiter public limiter: RiotRateLimiter
public config: JaxConfig public config: JaxConfig
public Account: AccountEndpoint
public League: LeagueEndpoint public League: LeagueEndpoint
public Match: MatchEndpoint public Match: MatchEndpoint
public MatchV4: MatchV4Endpoint public MatchV4: MatchV4Endpoint
@ -36,6 +37,7 @@ export default class Jax {
}) })
this.config = config this.config = config
this.Account = new AccountEndpoint(this.config, this.limiter)
this.League = new LeagueEndpoint(this.config, this.limiter) this.League = new LeagueEndpoint(this.config, this.limiter)
this.Match = new MatchEndpoint(this.config, this.limiter) this.Match = new MatchEndpoint(this.config, this.limiter)
this.MatchV4 = new MatchV4Endpoint(this.config, this.limiter) this.MatchV4 = new MatchV4Endpoint(this.config, this.limiter)

View file

@ -21,7 +21,7 @@ export default class JaxRequest {
endpoint: string, endpoint: string,
limiter: RiotRateLimiter, limiter: RiotRateLimiter,
cacheTime: number, cacheTime: number,
riotApiPath = `lol` riotApiPath = 'lol'
) { ) {
this.region = region this.region = region
this.config = config this.config = config

View file

@ -4,6 +4,7 @@ import { LeagueEntryDTO } from './Jax/src/Endpoints/LeagueEndpoint'
import Summoner from 'App/Models/Summoner' import Summoner from 'App/Models/Summoner'
import { PlayerRankParsed } from 'App/Parsers/ParsedType' import { PlayerRankParsed } from 'App/Parsers/ParsedType'
import MatchPlayerRank from 'App/Models/MatchPlayerRank' import MatchPlayerRank from 'App/Models/MatchPlayerRank'
import { ACCOUNT_NAME_DELIMITER } from 'App/helpers'
export interface LeagueEntriesByQueue { export interface LeagueEntriesByQueue {
soloQ?: LeagueEntryByQueue soloQ?: LeagueEntryByQueue
@ -53,22 +54,22 @@ class SummonerService {
} }
/** /**
* Get account infos for a searched summoner name * Get summnoner account infos for a searched summoner name
* @param summonerName * @param summonerName
* @param region * @param region
*/ */
public async getAccount(summonerName: string, region: string) { public async getSummoner(summonerName: string, region: string): Promise<SummonerDTO | null> {
const name = summonerName.toLowerCase() const name = summonerName.toLowerCase()
const account = await Jax.Summoner.summonerName(name, region)
return account
}
public async getRiotAccountByName(name: string, tagline: string, region: string) { // Get old way: summonerName
return await Jax.Summoner.puuidFromRiotTag(name, tagline, region) if (!name.includes(ACCOUNT_NAME_DELIMITER)) {
} return Jax.Summoner.summonerName(name, region)
}
public async getSummonerByPuuid(puuid: string, region: string) { // Get new way: gameName#tagLine
return await Jax.Summoner.summonerPuuid(puuid, region) 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
} }
/** /**

View file

@ -1,3 +1,8 @@
/**
* Delimiter used instead of '#' in account names from the Frontend
*/
export const ACCOUNT_NAME_DELIMITER = '-'
/** /**
* All League of Legends regions used in Riot API * All League of Legends regions used in Riot API
*/ */

View file

@ -37,7 +37,7 @@ export default class LoadV4Matches extends BaseCommand {
this.logger.info(`Trying to find ${this.summoner} from ${this.region}`) this.logger.info(`Trying to find ${this.summoner} from ${this.region}`)
// ACCOUNT // ACCOUNT
const account = await SummonerService.getAccount(this.summoner, this.region) const account = await SummonerService.getSummoner(this.summoner, this.region)
if (account) { if (account) {
this.logger.success('League account found.') this.logger.success('League account found.')
} else { } else {