diff --git a/server/app/Controllers/Http/MatchController.js b/server/app/Controllers/Http/MatchController.js index b222873..36d59e2 100644 --- a/server/app/Controllers/Http/MatchController.js +++ b/server/app/Controllers/Http/MatchController.js @@ -17,7 +17,7 @@ class MatchController { async _getPlayerRank(summoner, region) { const account = await SummonerService.getAccount(summoner.name, region) if (account) { - const ranked = await SummonerService.getRanked(account) + const ranked = await SummonerService.getRanked(account, region) summoner.rank = ranked.soloQ ? (({ tier, shortName }) => ({ tier, shortName }))(ranked.soloQ) : null } else { summoner.rank = null @@ -63,7 +63,7 @@ class MatchController { console.log('MATCH DETAILS ALREADY SAVED') matchDetails = alreadySaved } else { - matchDetails = await Jax.Match.get(gameId) + matchDetails = await Jax.Match.get(gameId, region) matchDetails = await DetailedMatchTransformer.transform(matchDetails) await DetailedMatch.create(matchDetails) } diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js index bd0a761..254e5ff 100644 --- a/server/app/Controllers/Http/SummonerController.js +++ b/server/app/Controllers/Http/SummonerController.js @@ -38,11 +38,11 @@ class SummonerController { ) // CURRENT GAME - const currentGame = await Jax.Spectator.summonerID(account.id) + const currentGame = await Jax.Spectator.summonerID(account.id, region) finalJSON.playing = !!currentGame // RANKED STATS - finalJSON.ranked = await SummonerService.getRanked(account) + finalJSON.ranked = await SummonerService.getRanked(account, region) // MATCH LIST await MatchService.updateMatchList(account, summonerDB) diff --git a/server/app/Services/MatchService.js b/server/app/Services/MatchService.js index 9eb625c..7e9a375 100644 --- a/server/app/Services/MatchService.js +++ b/server/app/Services/MatchService.js @@ -15,7 +15,7 @@ class MatchService { let alreadyIn = false let index = 0 do { - let newMatchList = (await Jax.Matchlist.accountID(account.accountId, index)).matches + let newMatchList = (await Jax.Matchlist.accountID(account.accountId, account.region, index)).matches matchList = [...matchList, ...newMatchList] alreadyIn = newMatchList.length === 0 || stopFetching(newMatchList) // If the match is made in another region : we stop fetching @@ -96,7 +96,7 @@ class MatchService { } } - const requests = matchesToGetFromRiot.map(Jax.Match.get) + const requests = matchesToGetFromRiot.map(gameId => Jax.Match.get(gameId, account.region)) let matchesFromApi = await Promise.all(requests) /* If we have to store some matches in the db */ diff --git a/server/app/Services/SummonerService.js b/server/app/Services/SummonerService.js index c26a8e9..7f145e1 100644 --- a/server/app/Services/SummonerService.js +++ b/server/app/Services/SummonerService.js @@ -34,7 +34,7 @@ class SummonerService { return JSON.parse(accountCache) } - const account = await Jax.Summoner.summonerName(name) + const account = await Jax.Summoner.summonerName(name, region) if (account) { await Redis.set(`${region}-${name}`, JSON.stringify(account), 'EX', 36000) } @@ -44,15 +44,16 @@ class SummonerService { /** * Get ranked data for a specific Summoner * @param account + * @param region */ - async getRanked(account) { + async getRanked(account, region) { const rankedCache = await Redis.get(`ranked-${account.puuid}`) if (rankedCache) { console.log('RANKED CACHED') return JSON.parse(rankedCache) } - const ranked = await Jax.League.summonerID(account.id) + const ranked = await Jax.League.summonerID(account.id, region) const result = { soloQ: this._getleagueData(ranked.find(e => e.queueType === 'RANKED_SOLO_5x5')) || null, flex5v5: this._getleagueData(ranked.find(e => e.queueType === 'RANKED_FLEX_SR')) || null, diff --git a/server/providers/Jax/src/Endpoints/LeagueEndpoint.js b/server/providers/Jax/src/Endpoints/LeagueEndpoint.js index bf19417..e74a6c0 100644 --- a/server/providers/Jax/src/Endpoints/LeagueEndpoint.js +++ b/server/providers/Jax/src/Endpoints/LeagueEndpoint.js @@ -6,8 +6,9 @@ class LeagueEndpoint { this.limiter = limiter } - summonerID(summonerID) { + summonerID(summonerID, region) { return new JaxRequest( + region, this.config, `league/v4/entries/by-summoner/${summonerID}`, this.limiter diff --git a/server/providers/Jax/src/Endpoints/MatchEndpoint.js b/server/providers/Jax/src/Endpoints/MatchEndpoint.js index 6ceff06..2be0e22 100644 --- a/server/providers/Jax/src/Endpoints/MatchEndpoint.js +++ b/server/providers/Jax/src/Endpoints/MatchEndpoint.js @@ -8,8 +8,9 @@ class MatchEndpoint { this.get = this.get.bind(this) } - get(matchID) { + get(matchID, region) { return new JaxRequest( + region, this.config, `match/v4/matches/${matchID}`, this.limiter diff --git a/server/providers/Jax/src/Endpoints/MatchlistEndpoint.js b/server/providers/Jax/src/Endpoints/MatchlistEndpoint.js index afab6d7..13dbf25 100644 --- a/server/providers/Jax/src/Endpoints/MatchlistEndpoint.js +++ b/server/providers/Jax/src/Endpoints/MatchlistEndpoint.js @@ -6,8 +6,9 @@ class MatchlistEndpoint { this.limiter = limiter } - accountID(accountID, beginIndex = 0) { + accountID(accountID, region, beginIndex = 0) { return new JaxRequest( + region, this.config, `match/v4/matchlists/by-account/${accountID}?beginIndex=${beginIndex}`, this.limiter diff --git a/server/providers/Jax/src/Endpoints/SpectatorEndpoint.js b/server/providers/Jax/src/Endpoints/SpectatorEndpoint.js index 8ffcb3a..b21c39d 100644 --- a/server/providers/Jax/src/Endpoints/SpectatorEndpoint.js +++ b/server/providers/Jax/src/Endpoints/SpectatorEndpoint.js @@ -6,8 +6,9 @@ class SpectatorEndpoint { this.limiter = limiter } - summonerID(summonerID) { + summonerID(summonerID, region) { return new JaxRequest( + region, this.config, `spectator/v4/active-games/by-summoner/${summonerID}`, this.limiter diff --git a/server/providers/Jax/src/Endpoints/SummonerEndpoint.js b/server/providers/Jax/src/Endpoints/SummonerEndpoint.js index 30821d4..58e39fc 100644 --- a/server/providers/Jax/src/Endpoints/SummonerEndpoint.js +++ b/server/providers/Jax/src/Endpoints/SummonerEndpoint.js @@ -6,8 +6,9 @@ class SummonerEndpoint { this.limiter = limiter } - summonerName(summonerName) { + summonerName(summonerName, region) { return new JaxRequest( + region, this.config, `summoner/v4/summoners/by-name/${encodeURI(summonerName)}`, this.limiter diff --git a/server/providers/Jax/src/JaxRequest.js b/server/providers/Jax/src/JaxRequest.js index 87d6102..07461db 100644 --- a/server/providers/Jax/src/JaxRequest.js +++ b/server/providers/Jax/src/JaxRequest.js @@ -1,7 +1,8 @@ const { promisify } = require('util') class JaxRequest { - constructor(config, endpoint, limiter) { + constructor(region, config, endpoint, limiter) { + this.region = region this.config = config this.endpoint = endpoint this.limiter = limiter @@ -13,7 +14,7 @@ class JaxRequest { async execute() { try { const resp = await this.limiter.executing({ - url: `https://${this.config.region}.api.riotgames.com/lol/${this.endpoint}`, + url: `https://${this.region}.api.riotgames.com/lol/${this.endpoint}`, token: this.config.key, resolveWithFullResponse: false })