mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: start using Cdragon instead of DDragon
Done Endpoints: Items and Perks
This commit is contained in:
parent
57e2fad45d
commit
8f19e570b7
4 changed files with 68 additions and 19 deletions
|
|
@ -12,14 +12,16 @@ class MatchTransformer {
|
|||
* Get global Context with DDragon Data
|
||||
*/
|
||||
async getContext() {
|
||||
const items = await Jax.DDragon.Item.list()
|
||||
const items = await Jax.CDragon.items()
|
||||
const champions = await Jax.DDragon.Champion.list()
|
||||
const runes = await Jax.DDragon.Rune.list()
|
||||
const perks = await Jax.CDragon.perks()
|
||||
const perkstyles = await Jax.CDragon.perkstyles()
|
||||
const version = Jax.DDragon.Version
|
||||
|
||||
this.champions = champions.data
|
||||
this.items = items.data
|
||||
this.runes = runes
|
||||
this.items = items
|
||||
this.perks = perks
|
||||
this.perkstyles = perkstyles.styles
|
||||
this.version = version
|
||||
}
|
||||
|
||||
|
|
@ -92,20 +94,16 @@ class MatchTransformer {
|
|||
stats.kp = totalKills === 0 ? 0 : +((stats.kills + stats.assists) * 100 / totalKills).toFixed(1)
|
||||
}
|
||||
|
||||
|
||||
let primaryRune = null
|
||||
let secondaryRune = null
|
||||
if (player.stats.perkPrimaryStyle) {
|
||||
const primaryRuneCategory = this.runes.find(r => r.id === player.stats.perkPrimaryStyle)
|
||||
for (const subCat of primaryRuneCategory.slots) {
|
||||
primaryRune = subCat.runes.find(r => r.id === player.stats.perk0)
|
||||
if (primaryRune) {
|
||||
break
|
||||
}
|
||||
}
|
||||
primaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${primaryRune.icon}`
|
||||
secondaryRune = this.runes.find(r => r.id === player.stats.perkSubStyle)
|
||||
secondaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${secondaryRune.icon}`
|
||||
const firstRune = this.perks.find(p => p.id === player.stats.perk0)
|
||||
const firstRuneUrl = firstRune.iconPath.split('/assets/')[1].toLowerCase()
|
||||
primaryRune = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${firstRuneUrl}`
|
||||
|
||||
const secondRuneStyle = this.perkstyles.find(p => p.id === player.stats.perkSubStyle)
|
||||
const secondRuneStyleUrl = secondRuneStyle.iconPath.split('/assets/')[1].toLowerCase()
|
||||
secondaryRune = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${secondRuneStyleUrl}`
|
||||
}
|
||||
|
||||
const items = []
|
||||
|
|
@ -115,11 +113,15 @@ class MatchTransformer {
|
|||
items.push(null)
|
||||
continue
|
||||
}
|
||||
|
||||
const item = this.items.find(i => i.id === id)
|
||||
const itemUrl = item.iconPath.split('/assets/')[1].toLowerCase()
|
||||
|
||||
items.push({
|
||||
image: `https://ddragon.leagueoflegends.com/cdn/${this.version}/img/item/${id}.png`,
|
||||
name: this.items[id].name,
|
||||
description: this.items[id].description,
|
||||
price: this.items[id].gold.total
|
||||
image: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${itemUrl}`,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
price: item.priceTotal
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
26
server/providers/Jax/src/CDragonRequest.js
Normal file
26
server/providers/Jax/src/CDragonRequest.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const got = require('got')
|
||||
|
||||
class CDragonRequest {
|
||||
constructor(endpoint) {
|
||||
this.endpoint = endpoint
|
||||
}
|
||||
|
||||
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/items.json
|
||||
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/perks.json
|
||||
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/perkstyles.json
|
||||
// https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json
|
||||
|
||||
async execute() {
|
||||
let url = `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/${this.endpoint}`
|
||||
|
||||
try {
|
||||
const response = await got(url);
|
||||
return JSON.parse(response.body)
|
||||
} catch (error) {
|
||||
console.log(error.response.body);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = CDragonRequest
|
||||
17
server/providers/Jax/src/Endpoints/CDragonEndpoint.js
Normal file
17
server/providers/Jax/src/Endpoints/CDragonEndpoint.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const CDragonRequest = require('../CDragonRequest')
|
||||
|
||||
class CDragonEndpoint {
|
||||
items() {
|
||||
return new CDragonRequest('items.json').execute()
|
||||
}
|
||||
|
||||
perks() {
|
||||
return new CDragonRequest('perks.json').execute()
|
||||
}
|
||||
|
||||
perkstyles() {
|
||||
return new CDragonRequest('perkstyles.json').execute()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CDragonEndpoint
|
||||
|
|
@ -10,6 +10,8 @@ const DDragonChampionEndpoint = require('./Endpoints/DDragonEndpoints/DDragonCha
|
|||
const DDragonRuneEndpoint = require('./Endpoints/DDragonEndpoints/DDragonRuneEndpoint')
|
||||
const DDragonItemEndpoint = require('./Endpoints/DDragonEndpoints/DDragonItemEndpoint')
|
||||
|
||||
const CDragonEndpoint = require('./Endpoints/CDragonEndpoint')
|
||||
|
||||
class Jax {
|
||||
constructor(config) {
|
||||
this.key = config.key
|
||||
|
|
@ -26,6 +28,8 @@ class Jax {
|
|||
this.Summoner = new SummonerEndpoint(this.config, this.limiter)
|
||||
|
||||
this.initDDragon()
|
||||
|
||||
this.CDragon = new CDragonEndpoint()
|
||||
}
|
||||
|
||||
async initDDragon() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue