const request = require('request') const fs = require('fs') const Level = require('../classes/Level.js') function xor(str, key) { return Buffer.from(String.fromCodePoint(...str.split('').map((char, i) => char.charCodeAt(0) ^ key.charCodeAt(i % key.length)))).toString('base64') } module.exports = async (app, req, res, api, analyze) => { if (app.offline) { if (!api) return res.redirect('search/' + req.params.id) else return res.send("-1") } let levelID = req.params.id if (levelID == "daily") return app.run.download(app, req, res, api, 'daily', analyze) else if (levelID == "weekly") return app.run.download(app, req, res, api, 'weekly', analyze) else if (levelID.match(/[^0-9]/)) { if (!api) return res.redirect('search/' + req.params.id) else return res.send("-1") } else levelID = levelID.replace(/[^0-9]/g, "") if (analyze || req.query.hasOwnProperty("download")) return app.run.download(app, req, res, api, levelID, analyze) request.post(app.endpoint + 'getGJLevels21.php', req.gdParams({ str: levelID, type: 0 }), async function (err, resp, body) { if (err || !body || body == '-1' || body.startsWith(" { let regex = new RegExp(`\\[\\[${x.toUpperCase()}\\]\\]`, "g") html = html.replace(regex, app.clean(level[x])) }) return res.send(html) }) } if (level.difficulty == "Extreme Demon") { request.get('http://www.pointercrate.com/api/v2/demons/?name=' + level.name.trim(), function (err, resp, demonList) { if (err) return sendLevel() let demon = JSON.parse(demonList) if (demon[0] && demon[0].position) level.demonList = demon[0].position return sendLevel() }) } else return sendLevel() }) }