2020-09-29 22:42:18 -03:00
|
|
|
module.exports = async (app, req, res) => {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2021-01-18 23:54:18 -03:00
|
|
|
if (req.offline) return res.send("-1")
|
2020-09-10 10:02:40 -03:00
|
|
|
|
2020-09-28 14:05:59 -03:00
|
|
|
let count = +req.query.count || 10
|
|
|
|
if (count > 1000) count = 1000
|
|
|
|
|
2020-11-01 17:29:32 -03:00
|
|
|
let params = req.gdParams({
|
2019-10-15 23:42:47 -03:00
|
|
|
userID : req.params.id,
|
|
|
|
accountID : req.params.id,
|
|
|
|
levelID: req.params.id,
|
2020-09-29 22:42:18 -03:00
|
|
|
page: +req.query.page || 0,
|
2020-09-28 14:05:59 -03:00
|
|
|
count,
|
2020-09-29 22:42:18 -03:00
|
|
|
mode: req.query.hasOwnProperty("top") ? "1" : "0",
|
|
|
|
})
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
let path = "getGJComments21"
|
|
|
|
if (req.query.type == "commentHistory") path = "getGJCommentHistory"
|
|
|
|
else if (req.query.type == "profile") path = "getGJAccountComments20"
|
|
|
|
|
2021-01-18 23:54:18 -03:00
|
|
|
req.gdRequest(path, params, function(err, resp, body) {
|
2019-10-15 23:42:47 -03:00
|
|
|
|
2019-11-10 18:18:52 -03:00
|
|
|
if (err || body == '-1' || !body) return res.send("-1")
|
2019-10-16 23:20:24 -03:00
|
|
|
|
|
|
|
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])
|
2019-12-22 00:16:18 -03:00
|
|
|
else comments = comments.filter(x => x[1] && x[1][1])
|
2019-10-16 23:20:24 -03:00
|
|
|
if (!comments.length) return res.send("-1")
|
|
|
|
|
2020-09-28 14:05:59 -03:00
|
|
|
let pages = body.split('#')[1].split(":")
|
|
|
|
let lastPage = +Math.ceil(+pages[0] / +pages[2]);
|
|
|
|
|
2019-10-16 23:20:24 -03:00
|
|
|
let commentArray = []
|
|
|
|
|
2020-09-28 14:05:59 -03:00
|
|
|
comments.forEach((c, i) => {
|
2019-10-16 23:20:24 -03:00
|
|
|
|
|
|
|
var x = c[0] //comment info
|
|
|
|
var y = c[1] //account info
|
|
|
|
|
2019-10-25 17:41:16 -03:00
|
|
|
if (!x[2]) return;
|
|
|
|
|
2019-10-16 23:20:24 -03:00
|
|
|
let comment = {}
|
2020-02-26 23:08:40 -03:00
|
|
|
comment.content = Buffer.from(x[2], 'base64').toString();
|
2019-11-17 19:00:19 -03:00
|
|
|
comment.ID = x[6]
|
2020-10-02 15:33:24 -03:00
|
|
|
comment.likes = +x[4]
|
2021-01-19 02:56:21 -03:00
|
|
|
comment.date = (x[9] || "?") + req.timestampSuffix
|
2019-12-25 18:20:32 -03:00
|
|
|
if (comment.content.endsWith("⍟") || comment.content.endsWith("☆")) {
|
2019-12-15 21:11:35 -03:00
|
|
|
comment.content = comment.content.slice(0, -1)
|
|
|
|
comment.browserColor = true
|
|
|
|
}
|
|
|
|
|
2019-10-15 23:42:47 -03:00
|
|
|
if (req.query.type != "profile") {
|
2019-10-16 23:20:24 -03:00
|
|
|
comment.username = y[1] || "Unknown"
|
2019-11-29 22:36:00 -03:00
|
|
|
comment.levelID = x[1] || req.params.id
|
2019-10-16 23:20:24 -03:00
|
|
|
comment.playerID = x[3]
|
|
|
|
comment.accountID = y[16]
|
2020-09-18 11:02:06 -03:00
|
|
|
comment.color = (comment.playerID == "16" ? "50,255,255" : x[12] || "255,255,255")
|
2020-10-02 15:33:24 -03:00
|
|
|
if (x[10] > 0) comment.percent = +x[10]
|
2020-09-18 11:02:06 -03:00
|
|
|
comment.moderator = +x[11] || 0
|
2020-11-12 22:32:15 -03:00
|
|
|
comment.icon = {
|
|
|
|
form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+y[14]],
|
2021-01-18 23:54:18 -03:00
|
|
|
icon: +y[9] || 1,
|
2020-11-12 22:32:15 -03:00
|
|
|
col1: +y[10],
|
|
|
|
col2: +y[11],
|
2021-01-18 23:54:18 -03:00
|
|
|
glow: +y[15] > 1
|
2020-11-12 22:32:15 -03:00
|
|
|
}
|
2019-10-15 23:42:47 -03:00
|
|
|
}
|
2019-11-29 22:36:00 -03:00
|
|
|
|
2020-09-28 14:05:59 -03:00
|
|
|
if (i == 0 && req.query.type != "commentHistory") {
|
|
|
|
comment.results = +pages[0];
|
|
|
|
comment.pages = lastPage;
|
2020-09-29 22:42:18 -03:00
|
|
|
comment.range = `${+pages[1] + 1} to ${Math.min(+pages[0], +pages[1] + +pages[2])}`
|
2020-09-28 14:05:59 -03:00
|
|
|
}
|
|
|
|
|
2019-10-16 23:20:24 -03:00
|
|
|
commentArray.push(comment)
|
2019-11-29 22:36:00 -03:00
|
|
|
|
2019-10-15 23:42:47 -03:00
|
|
|
})
|
|
|
|
|
2019-10-16 23:20:24 -03:00
|
|
|
return res.send(commentArray)
|
2019-10-15 23:42:47 -03:00
|
|
|
|
|
|
|
})
|
|
|
|
}
|