Use Jax wrapper to get summoners basic info

This commit is contained in:
Valentin Kaelin 2019-08-31 19:45:37 +02:00
parent e8aedda4fe
commit 312f7bb1a1
2 changed files with 20 additions and 14 deletions

View file

@ -5,11 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>riot-vue</title>
<title>LeagueStats</title>
</head>
<body>
<noscript>
<strong>We're sorry but riot-vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
<strong>We're sorry but LeagueStats doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->

View file

@ -55,34 +55,40 @@ app.post('/api', function (req, res) {
console.log('API Request');
console.log(req.body.summoner);
console.log(req.body.region);
//console.log(req.body.playerName);
console.time('all')
data.region = req.body.region;
data.username = req.body.summoner;
newVersion()
data.finalJSON = {};
getAccountInfos(res);
// getAccountInfos(res);
jax.regionName = data.region
getAccountInfosNew(res)
});
/* Get static file from Riot API */
app.post('/ddragon', async function (req, res) {
console.log('DDragon Request');
console.log('DDragon Request')
const endpoint = req.body.endpoint
const result = await jax.DDragon[endpoint].list()
res.send(result)
})
/* Refactor with the Jax Wrapper */
async function newVersion() {
jax.regionName = data.region
const { id, accountId } = await jax.Summoner.summonerName(data.username)
console.log(id, accountId)
/* Get account infos of an username - Refactor with the Jax Wrapper */
async function getAccountInfosNew(res) {
try {
const account = await jax.Summoner.summonerName(data.username)
data.summonerID = account.id
data.accountID = account.accountId
data.finalJSON.account = account
getRanked(res)
} catch (error) {
console.log('username not found')
console.log(error)
res.send(null)
}
}
// Get account infos of an username
// Get account infos of an username - Old version
const getAccountInfos = function (res) {
request(`https://${data.region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/${encodeURIComponent(data.username)}?api_key=${data.key}`, function (error, response, body) {
if (!error && response.statusCode == 200) {