GDBrowser/api/leaderboards/scores.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

const Player = require('../../classes/Player.js')
2021-12-19 23:23:50 -05:00
module.exports = async (app, req, res) => {
if (req.offline) return res.sendError()
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
else amount = count;
}
2021-01-11 16:00:21 -05:00
let params = {count: amount, type: "top"}
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"
else if (["global", "relative"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) {
params.type = "relative"
params.accountID = req.query.accountID
}
req.gdRequest('getGJScores20', params, function(err, resp, body) {
if (err) return res.sendError()
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.sendError()
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))
})
}