mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
Merge pull request #81 from zkxjzmswkwl/master
Addresses #80 "Update Search Functionality to Accommodate Riot IDs".
This commit is contained in:
commit
ceac859907
6 changed files with 62 additions and 5 deletions
|
|
@ -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('+', ' ')
|
const search = this.summoner.split(' ').join('').replace('+', ' ').replace('#', '-')
|
||||||
if (search.length) {
|
if (search.length) {
|
||||||
this.$emit('formSubmit', search, this.selectedRegion)
|
this.$emit('formSubmit', search, this.selectedRegion)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,31 @@ export default class SummonersController {
|
||||||
const { summoner, region } = await request.validate(SummonerBasicValidator)
|
const { summoner, region } = await request.validate(SummonerBasicValidator)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const account = await SummonerService.getAccount(summoner, region)
|
// 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the summoner is found
|
// Check if the summoner is found
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return response.json(null)
|
return response.json(null)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
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
|
||||||
|
|
@ -51,4 +52,25 @@ export default class SummonerEndpoint {
|
||||||
36000
|
36000
|
||||||
).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> {
|
||||||
|
return new JaxRequest(
|
||||||
|
region,
|
||||||
|
this.config,
|
||||||
|
`summoner/v4/summoners/by-puuid/${puuid}`,
|
||||||
|
this.limiter,
|
||||||
|
36000
|
||||||
|
).execute()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export default class JaxRequest {
|
||||||
private limiter: RiotRateLimiter
|
private limiter: RiotRateLimiter
|
||||||
private cacheTime: number
|
private cacheTime: number
|
||||||
private retries: number
|
private retries: number
|
||||||
|
private riotApiPath: string
|
||||||
private sleep: { (ms: number): Promise<void>; <T>(ms: number, value: T): Promise<T> }
|
private sleep: { (ms: number): Promise<void>; <T>(ms: number, value: T): Promise<T> }
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -19,7 +20,8 @@ export default class JaxRequest {
|
||||||
config: JaxConfig,
|
config: JaxConfig,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
limiter: RiotRateLimiter,
|
limiter: RiotRateLimiter,
|
||||||
cacheTime: number
|
cacheTime: number,
|
||||||
|
riotApiPath = `lol`
|
||||||
) {
|
) {
|
||||||
this.region = region
|
this.region = region
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|
@ -27,12 +29,13 @@ export default class JaxRequest {
|
||||||
this.limiter = limiter
|
this.limiter = limiter
|
||||||
this.cacheTime = cacheTime
|
this.cacheTime = cacheTime
|
||||||
this.retries = config.requestOptions.retriesBeforeAbort
|
this.retries = config.requestOptions.retriesBeforeAbort
|
||||||
|
this.riotApiPath = riotApiPath
|
||||||
|
|
||||||
this.sleep = promisify(setTimeout)
|
this.sleep = promisify(setTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute() {
|
public async execute() {
|
||||||
const url = `https://${this.region}.api.riotgames.com/lol/${this.endpoint}`
|
const url = `https://${this.region}.api.riotgames.com/${this.riotApiPath}/${this.endpoint}`
|
||||||
|
|
||||||
// Redis cache
|
// Redis cache
|
||||||
if (this.cacheTime > 0) {
|
if (this.cacheTime > 0) {
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,14 @@ class SummonerService {
|
||||||
return account
|
return account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the full list of old and actual summoner names
|
* Return the full list of old and actual summoner names
|
||||||
* @param account of the summoner
|
* @param account of the summoner
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export default class SummonerBasicValidator {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
summoner: schema.string({}, [rules.regex(/^[0-9\p{L} _\.]+$/u)]),
|
summoner: schema.string({}, [rules.regex(/^[0-9\p{L} _\.-]+$/u)]),
|
||||||
region: schema.string(),
|
region: schema.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue