mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: quickly adapt merged PR
This commit is contained in:
parent
ceac859907
commit
346273ef2d
9 changed files with 57 additions and 55 deletions
|
|
@ -110,15 +110,15 @@ export default {
|
|||
}
|
||||
},
|
||||
$route(newRoute) {
|
||||
this.summoner = newRoute.params.name
|
||||
this.summoner = newRoute.params.name.replaceAll('-', '#')
|
||||
this.dropdown = false
|
||||
this.open = false
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
if (!this.summoner.length && !this.homepage) {
|
||||
this.summoner = this.$route.params.name
|
||||
if (!this.summoner.length && !this.homepage && this.$route.params.name) {
|
||||
this.summoner = this.$route.params.name.replaceAll('-', '#')
|
||||
}
|
||||
window.addEventListener('blur', this.windowBlur)
|
||||
window.addEventListener('keydown', this.handleEscape)
|
||||
|
|
@ -148,7 +148,7 @@ export default {
|
|||
document.body.style.overflow = 'hidden'
|
||||
},
|
||||
formSubmit() {
|
||||
const search = this.summoner.split(' ').join('').replace('+', ' ').replace('#', '-')
|
||||
const search = this.summoner.split(' ').join('').replaceAll('+', ' ').replaceAll('#', '-')
|
||||
if (search.length) {
|
||||
this.$emit('formSubmit', search, this.selectedRegion)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,31 +35,7 @@ export default class SummonersController {
|
|||
const { summoner, region } = await request.validate(SummonerBasicValidator)
|
||||
|
||||
try {
|
||||
// Coming from C++ this seems completely fine. Which suggests to me that it likely isn't.
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
const account = await SummonerService.getSummoner(summoner, region)
|
||||
// Check if the summoner is found
|
||||
if (!account) {
|
||||
return response.json(null)
|
||||
|
|
|
|||
31
server/app/Services/Jax/src/Endpoints/AccountEndpoint.ts
Normal file
31
server/app/Services/Jax/src/Endpoints/AccountEndpoint.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
// import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
|
||||
import RiotRateLimiter from 'riot-ratelimiter'
|
||||
import { JaxConfig } from '../../JaxConfig'
|
||||
import JaxRequest from '../JaxRequest'
|
||||
import { getRiotRegion } from 'App/helpers'
|
||||
|
||||
export interface SummonerDTO {
|
||||
accountId: string
|
||||
|
|
@ -53,17 +51,6 @@ export default class SummonerEndpoint {
|
|||
).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> {
|
||||
return new JaxRequest(
|
||||
region,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import AccountEndpoint from './Endpoints/AccountEndpoint'
|
||||
import LeagueEndpoint from './Endpoints/LeagueEndpoint'
|
||||
import MatchEndpoint from './Endpoints/MatchEndpoint'
|
||||
import MatchlistEndpoint from './Endpoints/MatchlistEndpoint'
|
||||
|
|
@ -5,7 +6,6 @@ import SummonerEndpoint from './Endpoints/SummonerEndpoint'
|
|||
import SpectatorEndpoint from './Endpoints/SpectatorEndpoint'
|
||||
import CDragonEndpoint from './Endpoints/CDragonEndpoint'
|
||||
import { JaxConfig } from '../JaxConfig'
|
||||
// import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
|
||||
import RiotRateLimiter from 'riot-ratelimiter'
|
||||
import { STRATEGY } from 'riot-ratelimiter/dist/RateLimiter'
|
||||
import MatchV4Endpoint from './Endpoints/MatchV4Endpoint'
|
||||
|
|
@ -15,6 +15,7 @@ export default class Jax {
|
|||
public key: string
|
||||
public limiter: RiotRateLimiter
|
||||
public config: JaxConfig
|
||||
public Account: AccountEndpoint
|
||||
public League: LeagueEndpoint
|
||||
public Match: MatchEndpoint
|
||||
public MatchV4: MatchV4Endpoint
|
||||
|
|
@ -36,6 +37,7 @@ export default class Jax {
|
|||
})
|
||||
this.config = config
|
||||
|
||||
this.Account = new AccountEndpoint(this.config, this.limiter)
|
||||
this.League = new LeagueEndpoint(this.config, this.limiter)
|
||||
this.Match = new MatchEndpoint(this.config, this.limiter)
|
||||
this.MatchV4 = new MatchV4Endpoint(this.config, this.limiter)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export default class JaxRequest {
|
|||
endpoint: string,
|
||||
limiter: RiotRateLimiter,
|
||||
cacheTime: number,
|
||||
riotApiPath = `lol`
|
||||
riotApiPath = 'lol'
|
||||
) {
|
||||
this.region = region
|
||||
this.config = config
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { LeagueEntryDTO } from './Jax/src/Endpoints/LeagueEndpoint'
|
|||
import Summoner from 'App/Models/Summoner'
|
||||
import { PlayerRankParsed } from 'App/Parsers/ParsedType'
|
||||
import MatchPlayerRank from 'App/Models/MatchPlayerRank'
|
||||
import { ACCOUNT_NAME_DELIMITER } from 'App/helpers'
|
||||
|
||||
export interface LeagueEntriesByQueue {
|
||||
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 region
|
||||
*/
|
||||
public async getAccount(summonerName: string, region: string) {
|
||||
public async getSummoner(summonerName: string, region: string): Promise<SummonerDTO | null> {
|
||||
const name = summonerName.toLowerCase()
|
||||
const account = await Jax.Summoner.summonerName(name, region)
|
||||
return account
|
||||
|
||||
// Get old way: summonerName
|
||||
if (!name.includes(ACCOUNT_NAME_DELIMITER)) {
|
||||
return Jax.Summoner.summonerName(name, region)
|
||||
}
|
||||
|
||||
public async getRiotAccountByName(name: string, tagline: string, region: string) {
|
||||
return await Jax.Summoner.puuidFromRiotTag(name, tagline, region)
|
||||
}
|
||||
|
||||
public async getSummonerByPuuid(puuid: string, region: string) {
|
||||
return await Jax.Summoner.summonerPuuid(puuid, 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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export default class LoadV4Matches extends BaseCommand {
|
|||
this.logger.info(`Trying to find ${this.summoner} from ${this.region}`)
|
||||
|
||||
// ACCOUNT
|
||||
const account = await SummonerService.getAccount(this.summoner, this.region)
|
||||
const account = await SummonerService.getSummoner(this.summoner, this.region)
|
||||
if (account) {
|
||||
this.logger.success('League account found.')
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue