GDBrowser/api/leaderboardLevel.js
GDColon 58faaccc58 Error handling + quality of life changes
- Improved error handling (if err || !body || body == -1)
- Added list of text objects to analysis API (not on actual page, debating whether or not to even do that)
- Accounts with 65535 diamonds (integer limit) now display as '65535+'
2019-11-10 16:18:52 -05:00

42 lines
No EOL
1.1 KiB
JavaScript

const request = require('request')
module.exports = async (app, req, res) => {
let amount = 100;
let count = req.query.count ? parseInt(req.query.count) : null
if (count && count > 0) {
if (count > 200) amount = 200
else amount = count;
}
let params = {
levelID: req.params.id,
secret: app.secret,
accountID: app.id,
gjp: app.gjp,
type: req.query.hasOwnProperty("week") ? "2" : "1",
}
request.post('http://boomlings.com/database/getGJLevelScores211.php', {
form : params}, async function(err, resp, body) {
if (err || body == '-1' || !body) return res.send("-1")
scores = body.split('|').map(x => app.parseResponse(x))
if (!(scores.filter(x => x[1]).length)) return res.send("-1")
scores.forEach(x => {
let keys = Object.keys(x)
x.rank = x[6]
x.username = x[1]
x.percent = x[3]
x.coins = x[13]
x.playerID = x[2]
x.date = x[42] + " ago"
keys.forEach(k => delete x[k])
})
return res.send(scores.slice(0, amount))
})
}