2021-01-18 21:54:18 -05:00
|
|
|
let difficulties = ["auto", "easy", "normal", "hard", "harder", "insane", "demon", "demon-easy", "demon-medium", "demon-insane", "demon-extreme"]
|
|
|
|
let cache = {}
|
2020-11-02 11:16:35 -05:00
|
|
|
|
|
|
|
module.exports = async (app, req, res) => {
|
|
|
|
|
2021-12-07 14:14:56 -05:00
|
|
|
if (req.offline) return res.sendError()
|
2021-01-18 21:54:18 -05:00
|
|
|
|
|
|
|
let cached = cache[req.id]
|
2022-02-06 19:18:45 -05:00
|
|
|
if (app.config.cacheMapPacks && cached && cached.data && cached.indexed + 5000000 > Date.now()) return res.send(cached.data) // 1.5 hour cache
|
2021-01-18 21:54:18 -05:00
|
|
|
let params = { count: 250, page: 0 }
|
|
|
|
let packs = []
|
|
|
|
|
|
|
|
function mapPackLoop() {
|
|
|
|
req.gdRequest('getGJMapPacks21', params, function (err, resp, body) {
|
|
|
|
|
2021-12-07 14:14:56 -05:00
|
|
|
if (err) return res.sendError()
|
2021-01-18 21:54:18 -05:00
|
|
|
|
|
|
|
let newPacks = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[2])
|
|
|
|
packs = packs.concat(newPacks)
|
|
|
|
|
|
|
|
// not all GDPS'es support the count param, which means recursion time!!!
|
|
|
|
if (newPacks.length == 10) {
|
|
|
|
params.page++
|
|
|
|
return mapPackLoop()
|
|
|
|
}
|
|
|
|
|
|
|
|
let mappacks = packs.map(x => ({ // "packs.map()" laugh now please
|
|
|
|
id: +x[1],
|
|
|
|
name: x[2],
|
2021-07-07 20:58:31 -04:00
|
|
|
levels: x[3].split(","),
|
2021-01-18 21:54:18 -05:00
|
|
|
stars: +x[4],
|
|
|
|
coins: +x[5],
|
|
|
|
difficulty: difficulties[+x[6]] || "unrated",
|
|
|
|
barColor: x[7],
|
|
|
|
textColor: x[8]
|
|
|
|
}))
|
|
|
|
|
|
|
|
if (app.config.cacheMapPacks) cache[req.id] = {data: mappacks, indexed: Date.now()}
|
2022-02-06 19:18:45 -05:00
|
|
|
return res.send(mappacks)
|
2021-01-18 21:54:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
mapPackLoop()
|
2020-11-02 11:16:35 -05:00
|
|
|
}
|