const request = require('request') const fs = require('fs') const Level = require('../classes/Level.js') module.exports = async (app, req, res, api, ID, analyze) => { if (app.offline) { if (!api && levelID < 0) return res.redirect('/') if (!api) return res.redirect('search/' + req.params.id) else return res.send("-1") } let levelID = ID || req.params.id if (levelID == "daily") levelID = -1 else if (levelID == "weekly") levelID = -2 else levelID = levelID.replace(/[^0-9]/g, "") request.post(app.endpoint + 'downloadGJLevel22.php', req.gdParams({ levelID }), 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 (levelID < 0) { request.post(app.endpoint + 'getGJDailyLevel.php', req.gdParams({ weekly: levelID == -2 ? "1" : "0" }), async function (err, resp, dailyInfo) { if (err || dailyInfo == -1) return sendLevel() let dailyTime = dailyInfo.split("|")[1] level.nextDaily = +dailyTime level.nextDailyTimestamp = Math.round((Date.now() + (+dailyTime * 1000)) / 100000) * 100000 return sendLevel() }) } else if (level.difficulty == "Extreme Demon") { request.get('https://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() }) }) }) }) }