50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
|
module.exports = (app) : void => {
|
||
|
app.post('/' + app.get('config').addtopath + 'database/getGJComments21.php', async (req, res) => {
|
||
|
let comments = await app.get('db').collection('comments').find({
|
||
|
levelID: Number(req.body.levelID)
|
||
|
}).toArray();
|
||
|
|
||
|
let mode = 0;
|
||
|
let count = 10;
|
||
|
let offset = Number(req.body.page) * count;
|
||
|
|
||
|
if (req.body.mode)
|
||
|
mode = Number(req.body.mode);
|
||
|
|
||
|
if (req.body.count)
|
||
|
mode = Number(req.body.mode);
|
||
|
|
||
|
switch(mode) {
|
||
|
case 0:
|
||
|
comments.sort((a, b) => b.id - a.id);
|
||
|
break;
|
||
|
case 1:
|
||
|
comments.sort((a, b) => b.likes - a.likes);
|
||
|
}
|
||
|
|
||
|
const foundComments = comments
|
||
|
.slice(offset, offset + count);
|
||
|
|
||
|
if (foundComments.count <= 0)
|
||
|
return res.status(200).send('#0:0:0');
|
||
|
|
||
|
let commentString = foundComments.map(c => {
|
||
|
let result = '';
|
||
|
let uploadDate = new Date(c.uploadDate).toISOString();
|
||
|
let commentContent = c.commentContent;
|
||
|
|
||
|
if (Number(req.body.gameVersion) < 20)
|
||
|
commentContent = Buffer.from(commentContent, 'base64').toString('utf8');
|
||
|
|
||
|
result += `2~${commentContent}~3~${c.userID}~4~${c.likes}~5~0~7~${Number(c.isSpam)}~9~${uploadDate}~6~${c.id}~10~${c.percent}`;
|
||
|
|
||
|
// dummy data for now cus no users
|
||
|
result += `~11~0~12~0:1~oat~7~1~9~${Math.floor(Math.random() * 142) /* icon */}~10~${Math.floor(Math.random() * 64) /* color1 */}~11~${Math.floor(Math.random() * 64) /* color2 */}~14~${0 /* icontype */}~15~${1 /* special */}~16~${0 /*extID*/}`;
|
||
|
|
||
|
return result;
|
||
|
})
|
||
|
.join('|');
|
||
|
|
||
|
res.status(200).send(`${commentString}#${count}:${offset}:10`);
|
||
|
});
|
||
|
};
|