getGJComments implemented, and updateDJUserScore placeholder
This commit is contained in:
parent
0233b8fecb
commit
fce8db2c3e
|
@ -0,0 +1,50 @@
|
|||
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`);
|
||||
});
|
||||
};
|
|
@ -28,8 +28,13 @@ dbClient.connect((err) => {
|
|||
require('./getGJLevels21')(app);
|
||||
require('./uploadGJLevel21')(app);
|
||||
require('./downloadGJLevel22')(app);
|
||||
require('./getGJComments21')(app);
|
||||
require('./updateGJUserScore22')(app);
|
||||
|
||||
app.get('*', (req, res) => res.status(404).send('wrong page dumbass'));
|
||||
app.get('*', (req, res) => {
|
||||
console.log('got 404 for ' + req.url);
|
||||
res.status(404).send('wrong page dumbass');
|
||||
});
|
||||
|
||||
app.listen(config.port, () => {
|
||||
console.log(`expressjs server launched on port ${config.port}, gdps should now function properly`);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = (app): void => {
|
||||
app.post('/' + app.get('config').addtopath + 'database/updateGJUserScore22.php', async (req, res) => {
|
||||
res.status(200).send('0'); // temporary
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue