Better error handling + general cleanup #182
25 changed files with 117 additions and 95 deletions
12
.gitignore
vendored
12
.gitignore
vendored
|
@ -1,6 +1,9 @@
|
|||
# Ew
|
||||
extra
|
||||
|
||||
# Package manager lockfiles
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
||||
# Logs
|
||||
logs
|
||||
|
@ -40,9 +43,6 @@ build/Release
|
|||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
|
@ -60,6 +60,8 @@ typings/
|
|||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.*
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
# Editors
|
||||
.idea
|
||||
.vscode
|
|
@ -21,14 +21,14 @@ module.exports = async (app, req, res, level) => {
|
|||
const raw_data = level.data;
|
||||
|
||||
const response_data = analyze_level(level, raw_data);
|
||||
return res.send(response_data);
|
||||
return res.status(200).send(response_data);
|
||||
} else {
|
||||
zlib.unzip(levelString, (err, buffer) => {
|
||||
if (err) { return res.send("-2"); }
|
||||
if (err) { return res.status(500).send("-2"); }
|
||||
|
||||
const raw_data = buffer.toString();
|
||||
const response_data = analyze_level(level, raw_data);
|
||||
return res.send(response_data);
|
||||
return res.status(200).send(response_data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send("-1")
|
||||
if (req.offline) return res.status(500).send("-1")
|
||||
|
||||
let count = +req.query.count || 10
|
||||
if (count > 1000) count = 1000
|
||||
|
@ -20,14 +20,14 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest(path, req.gdParams(params), function(err, resp, body) {
|
||||
|
||||
if (err) return res.send("-1")
|
||||
if (err) return res.status(500).send("-1")
|
||||
|
||||
comments = body.split('|')
|
||||
comments = comments.map(x => x.split(':'))
|
||||
comments = comments.map(x => x.map(x => app.parseResponse(x, "~")))
|
||||
if (req.query.type == "profile") comments.filter(x => x[0][2])
|
||||
else comments = comments.filter(x => x[0] && x[0][2])
|
||||
if (!comments.length) return res.send("-1")
|
||||
if (!comments.length) return res.status(204).send("-1")
|
||||
|
||||
let pages = body.split('#')[1].split(":")
|
||||
let lastPage = +Math.ceil(+pages[0] / +pages[2]);
|
||||
|
@ -79,7 +79,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
})
|
||||
|
||||
return res.send(commentArray)
|
||||
return res.status(200).send(commentArray)
|
||||
|
||||
})
|
||||
}
|
|
@ -6,7 +6,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
|
|||
|
||||
function rejectLevel() {
|
||||
if (!api) return res.redirect('search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
else return res.status(500).send("-1")
|
||||
}
|
||||
|
||||
if (req.offline) {
|
||||
|
@ -22,7 +22,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
|
|||
req.gdRequest('downloadGJLevel22', { levelID }, function (err, resp, body) {
|
||||
|
||||
if (err) {
|
||||
if (analyze && api && req.server.downloadsDisabled) return res.send("-3")
|
||||
if (analyze && api && req.server.downloadsDisabled) return res.status(403).send("-3")
|
||||
else if (!api && levelID < 0) return res.redirect(`/?daily=${levelID * -1}`)
|
||||
else return rejectLevel()
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
|
|||
if (analyze) return app.run.analyze(app, req, res, level)
|
||||
|
||||
function sendLevel() {
|
||||
if (api) return res.send(level)
|
||||
if (api) return res.status(200).send(level)
|
||||
|
||||
else return fs.readFile('./html/level.html', 'utf8', function (err, data) {
|
||||
let html = data;
|
||||
|
@ -78,7 +78,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
|
|||
let regex = new RegExp(`\\[\\[${x.toUpperCase()}\\]\\]`, "g")
|
||||
html = html.replace(regex, app.clean(level[x]))
|
||||
})
|
||||
return res.send(html)
|
||||
return res.status(200).send(html)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -3,19 +3,19 @@ let gauntletNames = ["Fire", "Ice", "Poison", "Shadow", "Lava", "Bonus", "Chaos"
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send("-1")
|
||||
if (req.offline) return res.status(500).send("-1")
|
||||
|
||||
let cached = cache[req.id]
|
||||
if (app.config.cacheGauntlets && cached && cached.data && cached.indexed + 2000000 > Date.now()) return res.send(cached.data) // half hour cache
|
||||
if (app.config.cacheGauntlets && cached && cached.data && cached.indexed + 2000000 > Date.now()) return res.status(200).send(cached.data) // half hour cache
|
||||
|
||||
req.gdRequest('getGJGauntlets21', {}, function (err, resp, body) {
|
||||
|
||||
if (err) return res.send("-1")
|
||||
if (err) return res.status(500).send("-1")
|
||||
let gauntlets = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[3])
|
||||
let gauntletList = gauntlets.map(x => ({ id: +x[1], name: gauntletNames[+x[1] - 1] || "Unknown", levels: x[3].split(",") }))
|
||||
|
||||
if (app.config.cacheGauntlets) cache[req.id] = {data: gauntletList, indexed: Date.now()}
|
||||
res.send(gauntletList)
|
||||
res.status(200).send(gauntletList)
|
||||
|
||||
})
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ let caches = [{"stars": null, "coins": null, "demons": null, "diamonds": null},
|
|||
|
||||
module.exports = async (app, req, res, post) => {
|
||||
|
||||
if (req.isGDPS) return res.send("-2")
|
||||
if (!app.sheetsKey) return res.send([])
|
||||
// Accurate leaderboard returns 418 because private servers do not use.
|
||||
if (req.isGDPS) return res.status(418).send("-2")
|
||||
if (!app.sheetsKey) return res.status(500).send([])
|
||||
let gdMode = post || req.query.hasOwnProperty("gd")
|
||||
let modMode = !gdMode && req.query.hasOwnProperty("mod")
|
||||
let cache = caches[gdMode ? 2 : modMode ? 1 : 0]
|
||||
|
@ -18,7 +19,7 @@ module.exports = async (app, req, res, post) => {
|
|||
let type = req.query.type ? req.query.type.toLowerCase() : 'stars'
|
||||
if (type == "usercoins") type = "coins"
|
||||
if (!indexes.includes(type)) type = "stars"
|
||||
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type]) return res.send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache
|
||||
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type]) return res.status(200).send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache
|
||||
|
||||
sheet.useApiKey(app.sheetsKey)
|
||||
sheet.loadInfo().then(async () => {
|
||||
|
@ -29,7 +30,7 @@ module.exports = async (app, req, res, post) => {
|
|||
if (modMode) cellIndex += indexes.length
|
||||
|
||||
let cell = tab.getCell(1, cellIndex).value
|
||||
if (!cell || typeof cell != "string" || cell.startsWith("GoogleSpreadsheetFormulaError")) { console.log("Spreadsheet Error:"); console.log(cell); return res.send("-1") }
|
||||
if (!cell || typeof cell != "string" || cell.startsWith("GoogleSpreadsheetFormulaError")) { console.log("Spreadsheet Error:"); console.log(cell); return res.status(500).send("-1") }
|
||||
let leaderboard = JSON.parse(cell.replace(/~( |$)/g, ""))
|
||||
|
||||
let gdFormatting = ""
|
||||
|
@ -40,7 +41,7 @@ module.exports = async (app, req, res, post) => {
|
|||
caches[modMode ? 1 : 0][type] = JSON.stringify(leaderboard)
|
||||
caches[2][type] = gdFormatting
|
||||
lastIndex[modMode ? 1 : 0][type] = Date.now()
|
||||
return res.send(gdMode ? gdFormatting : leaderboard)
|
||||
return res.status(200).send(gdMode ? gdFormatting : leaderboard)
|
||||
|
||||
})
|
||||
}
|
|
@ -2,12 +2,13 @@ const request = require('request')
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.isGDPS) return res.send("0")
|
||||
// Accurate leaderboard returns 418 because Private servers do not use.
|
||||
if (req.isGDPS) return res.status(418).send("0")
|
||||
|
||||
request.post('http://robtopgames.com/Boomlings/get_scores.php', {
|
||||
form : { secret: app.config.params.secret || "Wmfd2893gb7", name: "Player" } }, function(err, resp, body) {
|
||||
|
||||
if (err || !body || body == 0) return res.send("0")
|
||||
if (err || !body || body == 0) return res.status(500).send("0")
|
||||
|
||||
let info = body.split(" ").filter(x => x.includes(";"))
|
||||
let users = []
|
||||
|
@ -36,7 +37,7 @@ module.exports = async (app, req, res) => {
|
|||
users.push(user)
|
||||
})
|
||||
|
||||
return res.send(users)
|
||||
return res.status(200).send(users)
|
||||
|
||||
})
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send("-1")
|
||||
if (req.offline) return res.status(500).send("-1")
|
||||
|
||||
let amount = 100;
|
||||
let count = req.query.count ? parseInt(req.query.count) : null
|
||||
|
@ -18,9 +18,9 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJLevelScores211', params, function(err, resp, body) {
|
||||
|
||||
if (err) return res.send({error: true, lastWorked: app.timeSince(req.id)})
|
||||
if (err) return res.status(500).send({error: true, lastWorked: app.timeSince(req.id)})
|
||||
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
|
||||
if (!scores.length) return res.send([])
|
||||
if (!scores.length) return res.status(500).send([])
|
||||
else app.trackSuccess(req.id)
|
||||
|
||||
scores.forEach(x => {
|
||||
|
@ -43,7 +43,7 @@ module.exports = async (app, req, res) => {
|
|||
app.userCache(req.id, x.accountID, x.playerID, x.username)
|
||||
})
|
||||
|
||||
return res.send(scores.slice(0, amount))
|
||||
return res.status(200).send(scores.slice(0, amount))
|
||||
|
||||
})
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send("-1")
|
||||
if (req.offline) return res.status(500).send("-1")
|
||||
|
||||
let amount = 100;
|
||||
let count = req.query.count ? parseInt(req.query.count) : null
|
||||
|
@ -16,9 +16,9 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJScores20', params, function(err, resp, body) {
|
||||
|
||||
if (err) return res.send("-1")
|
||||
if (err) return res.status(500).send("-1")
|
||||
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
|
||||
if (!scores.length) return res.send("-1")
|
||||
if (!scores.length) return res.status(500).send("-1")
|
||||
|
||||
scores.forEach(x => {
|
||||
let keys = Object.keys(x)
|
||||
|
@ -42,6 +42,6 @@ module.exports = async (app, req, res) => {
|
|||
keys.forEach(k => delete x[k])
|
||||
app.userCache(req.id, x.accountID, x.playerID, x.username)
|
||||
})
|
||||
return res.send(scores)
|
||||
return res.status(200).send(scores)
|
||||
})
|
||||
}
|
|
@ -6,7 +6,7 @@ module.exports = async (app, req, res, api, analyze) => {
|
|||
|
||||
function rejectLevel() {
|
||||
if (!api) return res.redirect('search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
else return res.status(500).send("-1")
|
||||
}
|
||||
|
||||
if (req.offline) return rejectLevel()
|
||||
|
@ -37,7 +37,7 @@ module.exports = async (app, req, res, api, analyze) => {
|
|||
|
||||
function sendLevel() {
|
||||
|
||||
if (api) return res.send(level)
|
||||
if (api) return res.status(200).send(level)
|
||||
|
||||
else return fs.readFile('./html/level.html', 'utf8', function (err, data) {
|
||||
let html = data;
|
||||
|
@ -50,7 +50,7 @@ module.exports = async (app, req, res, api, analyze) => {
|
|||
})
|
||||
if (req.server.downloadsDisabled) html = html.replace('id="additional" class="', 'id="additional" class="downloadDisabled ')
|
||||
.replace('analyzeBtn"', 'analyzeBtn" style="filter: opacity(30%)"')
|
||||
return res.send(html)
|
||||
return res.status(200).send(html)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@ let cache = {}
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send("-1")
|
||||
if (req.offline) return res.status(500).send("-1")
|
||||
|
||||
let cached = cache[req.id]
|
||||
if (app.config.cacheMapPacks && cached && cached.data && cached.indexed + 5000000 > Date.now()) return res.send(cached.data) // 1.5 hour cache
|
||||
if (app.config.cacheMapPacks && cached && cached.data && cached.indexed + 5000000 > Date.now()) return res.status(200).send(cached.data) // 1.5 hour cache
|
||||
let params = { count: 250, page: 0 }
|
||||
let packs = []
|
||||
|
||||
function mapPackLoop() {
|
||||
req.gdRequest('getGJMapPacks21', params, function (err, resp, body) {
|
||||
|
||||
if (err) return res.send("-1")
|
||||
if (err) return res.status(500).send("-1")
|
||||
|
||||
let newPacks = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[2])
|
||||
packs = packs.concat(newPacks)
|
||||
|
@ -36,7 +36,7 @@ module.exports = async (app, req, res) => {
|
|||
}))
|
||||
|
||||
if (app.config.cacheMapPacks) cache[req.id] = {data: mappacks, indexed: Date.now()}
|
||||
return res.send(mappacks)
|
||||
return res.status(200).send(mappacks)
|
||||
})
|
||||
}
|
||||
mapPackLoop()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
if (!req.body.password) return res.status(400).send("No password provided!")
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = async (app, req, res, api) => {
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
if (!req.body.password) return res.status(400).send("No password provided!")
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = async (app, req, res, api) => {
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
if (!req.body.password) return res.status(400).send("No password provided!")
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = async (app, req, res, api) => {
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (req.body.count) return app.run.countMessages(app, req, res)
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = async (app, req, res, api) => {
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.targetID) return res.status(400).send("No target ID provided!")
|
||||
if (!req.body.message) return res.status(400).send("No message provided!")
|
||||
|
|
|
@ -3,6 +3,8 @@ function sha1(data) { return crypto.createHash("sha1").update(data, "binary").di
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.ID) return res.status(400).send("No ID provided!")
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
if (!req.body.password) return res.status(400).send("No password provided!")
|
||||
|
|
|
@ -11,6 +11,8 @@ function getTime(time) {
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.comment) return res.status(400).send("No comment provided!")
|
||||
if (!req.body.username) return res.status(400).send("No username provided!")
|
||||
if (!req.body.levelID) return res.status(400).send("No level ID provided!")
|
||||
|
|
|
@ -3,6 +3,8 @@ function sha1(data) { return crypto.createHash("sha1").update(data, "binary").di
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.method !== 'POST') return res.status(405).send("Method not allowed.")
|
||||
|
||||
if (!req.body.comment) return res.status(400).send("No comment provided!")
|
||||
if (!req.body.username) return res.status(400).send("No username provided!")
|
||||
if (!req.body.accountID) return res.status(400).send("No account ID provided!")
|
||||
|
|
|
@ -4,7 +4,7 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
|
||||
if (req.offline) {
|
||||
if (!api) return res.redirect('/search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
else return res.status(500).send("-1")
|
||||
}
|
||||
|
||||
let username = getLevels || req.params.id
|
||||
|
@ -42,7 +42,7 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
|
||||
if (err2 || dumbGDPSError) {
|
||||
if (!api) return res.redirect('/search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
else return res.status(500).send("-1")
|
||||
}
|
||||
|
||||
if (!foundID) app.userCache(req.id, account[16], account[2], account[1])
|
||||
|
@ -78,7 +78,7 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
glow: account[28] == "1",
|
||||
}
|
||||
|
||||
if (api) return res.send(userData)
|
||||
if (api) return res.status(200).send(userData)
|
||||
|
||||
else fs.readFile('./html/profile.html', 'utf8', function(err, data) {
|
||||
let html = data;
|
||||
|
@ -87,7 +87,7 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
let regex = new RegExp(`\\[\\[${x.toUpperCase()}\\]\\]`, "g")
|
||||
html = html.replace(regex, app.clean(userData[x]))
|
||||
})
|
||||
return res.send(html)
|
||||
return res.status(200).send(html)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -5,17 +5,17 @@ let demonList = {}
|
|||
|
||||
module.exports = async (app, req, res) => {
|
||||
|
||||
if (req.offline) return res.send(req.query.hasOwnProperty("err") ? "err" : "-1")
|
||||
if (req.offline) return res.status(500).send(req.query.hasOwnProperty("err") ? "err" : "-1")
|
||||
|
||||
let demonMode = req.query.hasOwnProperty("demonlist") || req.query.hasOwnProperty("demonList") || req.query.type == "demonlist" || req.query.type == "demonList"
|
||||
if (demonMode) {
|
||||
if (!req.server.demonList) return res.send('-1')
|
||||
if (!req.server.demonList) return res.status(400).send('-1')
|
||||
let dList = demonList[req.id]
|
||||
if (!dList || !dList.list.length || dList.lastUpdated + 600000 < Date.now()) { // 10 minute cache
|
||||
return request.get(req.server.demonList + 'api/v2/demons/listed/?limit=100', function (err1, resp1, list1) {
|
||||
if (err1) return res.send("-1")
|
||||
if (err1) return res.status(500).send("-1")
|
||||
else return request.get(req.server.demonList + 'api/v2/demons/listed/?limit=100&after=100', function (err2, resp2, list2) {
|
||||
if (err2) return res.send("-1")
|
||||
if (err2) return res.status(500).send("-1")
|
||||
demonList[req.id] = {list: JSON.parse(list1).concat(JSON.parse(list2)).map(x => String(x.level_id)), lastUpdated: Date.now()}
|
||||
return app.run.search(app, req, res)
|
||||
})
|
||||
|
@ -85,7 +85,7 @@ module.exports = async (app, req, res) => {
|
|||
filters.str = demonMode ? demonList[req.id].list : filters.str.split(",")
|
||||
listSize = filters.str.length
|
||||
filters.str = filters.str.slice(filters.page*amount, filters.page*amount + amount)
|
||||
if (!filters.str.length) return res.send("-1")
|
||||
if (!filters.str.length) return res.status(400).send("-1")
|
||||
filters.str = filters.str.map(x => String(Number(x) + (+req.query.l || 0))).join()
|
||||
filters.page = 0
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJLevels21', req.gdParams(filters), function(err, resp, body) {
|
||||
|
||||
if (err) return res.send("-1")
|
||||
if (err) return res.status(500).send("-1")
|
||||
let splitBody = body.split('#')
|
||||
let preRes = splitBody[0].split('|')
|
||||
let authorList = {}
|
||||
|
@ -154,7 +154,7 @@ module.exports = async (app, req, res) => {
|
|||
})
|
||||
|
||||
if (filters.type == 10) parsedLevels = parsedLevels.slice((+filters.page) * amount, (+filters.page + 1) * amount)
|
||||
return res.send(parsedLevels)
|
||||
return res.status(200).send(parsedLevels)
|
||||
|
||||
})
|
||||
}
|
|
@ -4,14 +4,15 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
// temporary solution until song api is re-enabled
|
||||
|
||||
if (req.offline) return res.send('-1')
|
||||
if (req.offline) return res.status(500).send('-1')
|
||||
|
||||
let songID = req.params.song
|
||||
req.gdRequest('getGJSongInfo', {songID: songID}, function(err, resp, body) {
|
||||
if (err) return res.send('-1')
|
||||
if (err) return res.status(400).send('-1')
|
||||
else if (body < 0) return res.send(false)
|
||||
request.get('https://www.newgrounds.com/audio/listen/' + songID, function(err2, resp2, song) {
|
||||
return res.send(resp2.statusCode == 200)
|
||||
console.log(resp2.statusCode)
|
||||
return res.status(200).send(resp2.statusCode == 200)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
65
index.js
65
index.js
|
@ -184,8 +184,8 @@ app.clean = function(text) {if (!text || typeof text != "string") return text; e
|
|||
app.use('/assets', express.static(__dirname + '/assets', {maxAge: "7d"}));
|
||||
app.use('/assets/css', express.static(__dirname + '/assets/css')); // override maxAge
|
||||
|
||||
app.get("/sizecheck.js", function(req, res) { res.sendFile(__dirname + "/misc/sizecheck.js") })
|
||||
app.get("/dragscroll.js", function(req, res) { res.sendFile(__dirname + "/misc/dragscroll.js") })
|
||||
app.get("/sizecheck.js", function(req, res) { res.status(200).sendFile(__dirname + "/misc/sizecheck.js") })
|
||||
app.get("/dragscroll.js", function(req, res) { res.status(200).sendFile(__dirname + "/misc/dragscroll.js") })
|
||||
|
||||
app.get("/assets/:dir*?", function(req, res) {
|
||||
let main = (req.params.dir || "").toLowerCase()
|
||||
|
@ -193,10 +193,10 @@ app.get("/assets/:dir*?", function(req, res) {
|
|||
|
||||
if (dir.includes('.') || !req.path.endsWith("/")) {
|
||||
if (!req.params[0]) main = ""
|
||||
if (req.params.dir == "deatheffects" || req.params.dir == "trails") return res.sendFile(__dirname + "/assets/deatheffects/0.png")
|
||||
else if (req.params.dir == "gdps" && req.params[0].endsWith("_icon.png")) return res.sendFile(__dirname + "/assets/gdps/unknown_icon.png")
|
||||
else if (req.params.dir == "gdps" && req.params[0].endsWith("_logo.png")) return res.sendFile(__dirname + "/assets/gdps/unknown_logo.png")
|
||||
return res.send(`<p style="font-size: 20px; font-family: aller, helvetica, arial">Looks like this file doesn't exist ¯\\_(ツ)_/¯<br><a href='/assets/${main}'>View directory listing for <b>/assets/${main}</b></a></p>`)
|
||||
if (req.params.dir == "deatheffects" || req.params.dir == "trails") return res.status(200).sendFile(__dirname + "/assets/deatheffects/0.png")
|
||||
else if (req.params.dir == "gdps" && req.params[0].endsWith("_icon.png")) return res.status(200).sendFile(__dirname + "/assets/gdps/unknown_icon.png")
|
||||
else if (req.params.dir == "gdps" && req.params[0].endsWith("_logo.png")) return res.status(200).sendFile(__dirname + "/assets/gdps/unknown_logo.png")
|
||||
return res.status(404).send(`<p style="font-size: 20px; font-family: aller, helvetica, arial">Looks like this file doesn't exist ¯\\_(ツ)_/¯<br><a href='/assets/${main}'>View directory listing for <b>/assets/${main}</b></a></p>`)
|
||||
}
|
||||
|
||||
let path = `./assets/${dir}`
|
||||
|
@ -205,7 +205,7 @@ app.get("/assets/:dir*?", function(req, res) {
|
|||
|
||||
assetPage = fs.readFileSync('./html/assets.html', 'utf8')
|
||||
let assetData = JSON.stringify({files: files.filter(x => x.includes('.')), directories: files.filter(x => !x.includes('.'))})
|
||||
res.send(assetPage.replace('{NAME}', dir || "assets").replace('{DATA}', assetData))
|
||||
res.status(200).send(assetPage.replace('{NAME}', dir || "assets").replace('{DATA}', assetData))
|
||||
})
|
||||
|
||||
|
||||
|
@ -230,7 +230,7 @@ let downloadDisabled = ['daily', 'weekly']
|
|||
let gdpsHide = ['achievements', 'messages']
|
||||
|
||||
app.get("/", function(req, res) {
|
||||
if (req.query.hasOwnProperty("offline") || (req.offline && !req.query.hasOwnProperty("home"))) res.sendFile(__dirname + "/html/offline.html")
|
||||
if (req.query.hasOwnProperty("offline") || (req.offline && !req.query.hasOwnProperty("home"))) res.status(200).sendFile(__dirname + "/html/offline.html")
|
||||
else {
|
||||
fs.readFile('./html/home.html', 'utf8', function (err, data) {
|
||||
let html = data;
|
||||
|
@ -249,26 +249,26 @@ app.get("/", function(req, res) {
|
|||
html = html.replace('id="dl" style="display: none', 'style="display: block')
|
||||
.replace('No active <span id="noLevel">daily</span> level!', '[Blocked by RobTop]')
|
||||
}
|
||||
return res.send(html)
|
||||
return res.status(200).send(html)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
app.get("/achievements", function(req, res) { res.sendFile(__dirname + "/html/achievements.html") })
|
||||
app.get("/analyze/:id", function(req, res) { res.sendFile(__dirname + "/html/analyze.html") })
|
||||
app.get("/api", function(req, res) { res.sendFile(__dirname + "/html/api.html") })
|
||||
app.get("/boomlings", function(req, res) { res.sendFile(__dirname + "/html/boomlings.html") })
|
||||
app.get("/comments/:id", function(req, res) { res.sendFile(__dirname + "/html/comments.html") })
|
||||
app.get("/demon/:id", function(req, res) { res.sendFile(__dirname + "/html/demon.html") })
|
||||
app.get("/gauntlets", function(req, res) { res.sendFile(__dirname + "/html/gauntlets.html") })
|
||||
app.get("/gdps", function(req, res) { res.sendFile(__dirname + "/html/gdps.html") })
|
||||
app.get("/iconkit", function(req, res) { res.sendFile(__dirname + "/html/iconkit.html") })
|
||||
app.get("/leaderboard", function(req, res) { res.sendFile(__dirname + "/html/leaderboard.html") })
|
||||
app.get("/leaderboard/:text", function(req, res) { res.sendFile(__dirname + "/html/levelboard.html") })
|
||||
app.get("/mappacks", function(req, res) { res.sendFile(__dirname + "/html/mappacks.html") })
|
||||
app.get("/messages", function(req, res) { res.sendFile(__dirname + "/html/messages.html") })
|
||||
app.get("/search", function(req, res) { res.sendFile(__dirname + "/html/filters.html") })
|
||||
app.get("/search/:text", function(req, res) { res.sendFile(__dirname + "/html/search.html") })
|
||||
app.get("/achievements", function(req, res) { res.status(200).sendFile(__dirname + "/html/achievements.html") })
|
||||
app.get("/analyze/:id", function(req, res) { res.status(200).sendFile(__dirname + "/html/analyze.html") })
|
||||
app.get("/api", function(req, res) { res.status(200).sendFile(__dirname + "/html/api.html") })
|
||||
app.get("/boomlings", function(req, res) { res.status(200).sendFile(__dirname + "/html/boomlings.html") })
|
||||
app.get("/comments/:id", function(req, res) { res.status(200).sendFile(__dirname + "/html/comments.html") })
|
||||
app.get("/demon/:id", function(req, res) { res.status(200).sendFile(__dirname + "/html/demon.html") })
|
||||
app.get("/gauntlets", function(req, res) { res.status(200).sendFile(__dirname + "/html/gauntlets.html") })
|
||||
app.get("/gdps", function(req, res) { res.status(200).sendFile(__dirname + "/html/gdps.html") })
|
||||
app.get("/iconkit", function(req, res) { res.status(200).sendFile(__dirname + "/html/iconkit.html") })
|
||||
app.get("/leaderboard", function(req, res) { res.status(200).sendFile(__dirname + "/html/leaderboard.html") })
|
||||
app.get("/leaderboard/:text", function(req, res) { res.status(200).sendFile(__dirname + "/html/levelboard.html") })
|
||||
app.get("/mappacks", function(req, res) { res.status(200).sendFile(__dirname + "/html/mappacks.html") })
|
||||
app.get("/messages", function(req, res) { res.status(200).sendFile(__dirname + "/html/messages.html") })
|
||||
app.get("/search", function(req, res) { res.status(200).sendFile(__dirname + "/html/filters.html") })
|
||||
app.get("/search/:text", function(req, res) { res.status(200).sendFile(__dirname + "/html/search.html") })
|
||||
|
||||
|
||||
// API
|
||||
|
@ -276,7 +276,7 @@ app.get("/search/:text", function(req, res) { res.sendFile(__dirname + "/html/se
|
|||
app.get("/api/analyze/:id", RL, function(req, res) { app.run.level(app, req, res, true, true) })
|
||||
app.get("/api/boomlings", function(req, res) { app.run.boomlings(app, req, res) })
|
||||
app.get("/api/comments/:id", RL2, function(req, res) { app.run.comments(app, req, res) })
|
||||
app.get("/api/credits", function(req, res) { res.send(require('./misc/credits.json')) })
|
||||
app.get("/api/credits", function(req, res) { res.status(200).send(require('./misc/credits.json')) })
|
||||
app.get("/api/gauntlets", function(req, res) { app.run.gauntlets(app, req, res) })
|
||||
app.get("/api/leaderboard", function(req, res) { app.run[req.query.hasOwnProperty("accurate") ? "accurate" : "scores"](app, req, res) })
|
||||
app.get("/api/leaderboardLevel/:id", RL2, function(req, res) { app.run.leaderboardLevel(app, req, res) })
|
||||
|
@ -310,24 +310,23 @@ app.get("/:id", function(req, res) { app.run.level(app, req, res) })
|
|||
// MISC
|
||||
|
||||
app.get("/icon/:text", function(req, res) { app.run.icon(app, req, res) })
|
||||
app.get("/api/userCache", function(req, res) { res.send(app.accountCache) })
|
||||
app.get("/api/achievements", function(req, res) { res.send({achievements, types: achievementTypes, shopIcons, colors: colorList }) })
|
||||
app.get("/api/music", function(req, res) { res.send(music) })
|
||||
app.get("/api/gdps", function(req, res) {res.send(req.query.hasOwnProperty("current") ? app.safeServers.find(x => req.server.id == x.id) : app.safeServers) })
|
||||
app.get("/api/userCache", function(req, res) { res.status(200).send(app.accountCache) })
|
||||
app.get("/api/achievements", function(req, res) { res.status(200).send({achievements, types: achievementTypes, shopIcons, colors: colorList }) })
|
||||
app.get("/api/music", function(req, res) { res.status(200).send(music) })
|
||||
app.get("/api/gdps", function(req, res) {res.status(200).send(req.query.hasOwnProperty("current") ? app.safeServers.find(x => req.server.id == x.id) : app.safeServers) })
|
||||
app.get('/api/icons', function(req, res) {
|
||||
let sample = [JSON.stringify(sampleIcons[Math.floor(Math.random() * sampleIcons.length)].slice(1))]
|
||||
let iconserver = req.isGDPS ? req.server.name : undefined
|
||||
res.send({icons: gdIcons, colors: colorList, colorOrder, whiteIcons, server: iconserver, noCopy: req.onePointNine || req.offline, sample});
|
||||
res.status(200).send({icons: gdIcons, colors: colorList, colorOrder, whiteIcons, server: iconserver, noCopy: req.onePointNine || req.offline, sample});
|
||||
});
|
||||
|
||||
app.get('*', function(req, res) {
|
||||
if (req.path.startsWith('/api')) res.send('-1')
|
||||
if (req.path.startsWith('/api')) res.status(404).send('-1')
|
||||
else res.redirect('/search/404%20')
|
||||
});
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
if (err && err.message == "Response timeout") res.status(500).send('Internal server error! (Timed out)')
|
||||
else if (err) console.log(err)
|
||||
if (err && err.message == "Response timeout") res.status(504).send('Internal server error! (Timed out)')
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (e) => { console.log(e) });
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "node ./index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ag-psd": "^14.3.2",
|
||||
"canvas": "^2.8.0",
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"targetAccountID": "targetBddpvouKE"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "1.9 GDPS",
|
||||
"link": "https://absolllute.com/gdps/",
|
||||
|
|
Loading…
Add table
Reference in a new issue