2021-12-29 11:02:34 -06:00
|
|
|
const Player = require('../../classes/Player.js')
|
2021-12-19 23:23:50 -05:00
|
|
|
|
2019-10-16 18:47:53 -04:00
|
|
|
module.exports = async (app, req, res) => {
|
2019-10-15 22:42:47 -04:00
|
|
|
|
2021-12-07 14:14:56 -05:00
|
|
|
if (req.offline) return res.sendError()
|
2020-09-10 09:02:40 -04:00
|
|
|
|
2019-10-15 22:42:47 -04:00
|
|
|
let amount = 100;
|
|
|
|
let count = req.query.count ? parseInt(req.query.count) : null
|
|
|
|
if (count && count > 0) {
|
2021-09-02 19:07:31 -04:00
|
|
|
if (count > 10000) amount = 10000
|
2019-10-15 22:42:47 -04:00
|
|
|
else amount = count;
|
|
|
|
}
|
|
|
|
|
2021-01-11 16:00:21 -05:00
|
|
|
let params = {count: amount, type: "top"}
|
2019-10-15 22:42:47 -04:00
|
|
|
|
2021-01-11 16:00:21 -05:00
|
|
|
if (["creators", "creator", "cp"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) params.type = "creators"
|
2021-01-22 22:28:26 -05:00
|
|
|
else if (["week", "weekly"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) params.type = "week"
|
2021-12-29 11:02:34 -06:00
|
|
|
else if (["global", "relative"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) {
|
|
|
|
params.type = "relative"
|
|
|
|
params.accountID = req.query.accountID
|
|
|
|
}
|
2021-01-07 10:38:55 -05:00
|
|
|
|
2021-01-18 21:54:18 -05:00
|
|
|
req.gdRequest('getGJScores20', params, function(err, resp, body) {
|
2019-10-15 22:42:47 -04:00
|
|
|
|
2021-12-07 14:14:56 -05:00
|
|
|
if (err) return res.sendError()
|
2019-10-15 22:42:47 -04:00
|
|
|
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
|
2021-12-07 14:14:56 -05:00
|
|
|
if (!scores.length) return res.sendError()
|
2019-10-15 22:42:47 -04:00
|
|
|
|
2021-12-29 11:02:34 -06:00
|
|
|
scores = scores.map(x => new Player(x))
|
|
|
|
scores.forEach(x => app.userCache(req.id, x.accountID, x.playerID, x.username))
|
2022-02-06 19:18:45 -05:00
|
|
|
return res.send(scores.slice(0, amount))
|
2021-12-29 11:02:34 -06:00
|
|
|
})
|
2019-10-15 22:42:47 -04:00
|
|
|
}
|