|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import * as hash from './hash';
|
|
|
|
|
|
|
|
|
|
const levelsPerPage = 10; // should be kept at 10, increasing/decreasing may lead to unforseeable consequences
|
|
|
|
|
const handleRequestsAt = ['getGJLevels21', 'getGJLevels20', 'getGJLevels19', 'getGJLevels'];
|
|
|
|
|
|
|
|
|
|
module.exports = (app) : void => {
|
|
|
|
|
app.post('/' + app.get('config').addtopath + 'database/getGJLevels21.php', async (req, res) => {
|
|
|
|
|
let getLevels = async (req, res) => {
|
|
|
|
|
let levelsString = '';
|
|
|
|
|
|
|
|
|
|
let searchQuery: any = {}; // fuck you typescript, i have to use any or else it screams
|
|
|
|
@ -16,7 +17,7 @@ module.exports = (app) : void => {
|
|
|
|
|
if (req.body.epic != '0') searchQuery.epic = true;
|
|
|
|
|
if (req.body.coins != '0') searchQuery.coins = true;
|
|
|
|
|
if (req.body.twoPlayer != '0') searchQuery.twoPlayer = true;
|
|
|
|
|
if (req.body.star) searchQuery.stars = {$gt: 0};
|
|
|
|
|
if (req.body.star) searchQuery.stars = { $gt: 0 };
|
|
|
|
|
if (req.body.original != '0') searchQuery.original = 0;
|
|
|
|
|
if (req.body.noStar) searchQuery.stars = 0;
|
|
|
|
|
|
|
|
|
@ -33,19 +34,19 @@ module.exports = (app) : void => {
|
|
|
|
|
searchQuery.auto = false;
|
|
|
|
|
if (req.body.diff == '-1') { // NA levels
|
|
|
|
|
searchQuery.difficulty = 0;
|
|
|
|
|
} else if(req.body.diff == '-2') { // demons
|
|
|
|
|
} else if (req.body.diff == '-2') { // demons
|
|
|
|
|
if (req.body.demonFilter) {
|
|
|
|
|
searchQuery.difficulty = 60 + req.body.demonFilter * 10;
|
|
|
|
|
} else {
|
|
|
|
|
searchQuery.difficulty = { $gte: 60 };
|
|
|
|
|
}
|
|
|
|
|
} else if(req.body.diff == '-3') { // auto
|
|
|
|
|
} else if (req.body.diff == '-3') { // auto
|
|
|
|
|
searchQuery.auto = true;
|
|
|
|
|
} else {
|
|
|
|
|
searchQuery.$or = req.body.diff
|
|
|
|
|
.split(',') // multiple diffs
|
|
|
|
|
.map(d => {
|
|
|
|
|
return {difficulty: Number(d) * 10};
|
|
|
|
|
return { difficulty: Number(d) * 10 };
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -55,8 +56,8 @@ module.exports = (app) : void => {
|
|
|
|
|
$and: [
|
|
|
|
|
{
|
|
|
|
|
$or: [
|
|
|
|
|
{id: Number(req.body.str)},
|
|
|
|
|
{name: {$regex: `${req.body.str}`}}
|
|
|
|
|
{ id: Number(req.body.str) },
|
|
|
|
|
{ name: { $regex: `${req.body.str}` } }
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
searchQuery
|
|
|
|
@ -111,21 +112,24 @@ module.exports = (app) : void => {
|
|
|
|
|
.slice(offset, (Number(req.body.page) + 1) * levelsPerPage - 1);
|
|
|
|
|
|
|
|
|
|
let results = foundLevels
|
|
|
|
|
.map(l =>
|
|
|
|
|
.map(l =>
|
|
|
|
|
`1:${l.id}:2:${l.name}:5:${l.version}:6:${l.userID}:8:10:9:${l.difficulty}:10:${l.downloads}:12:${l.audioTrack}:13:${l.gameVersion}:14:${l.likes}:17:${Number(l.difficulty >= 60)}:43:${Math.max(l.difficulty - 60, 0)}:25:${Number(l.auto)}:18:${l.stars}:19:${Number(l.featured)}:42:${Number(l.epic)}:45:${l.objects}:3:${l.description}:15:${l.length}:30:${l.original}:31:0:37:${l.coins}:38:${Number(l.ratedCoins)}:39:${l.requestedStars}:46:1:47:2:40:${Number(l.hasLDM)}:35:${l.songID}`
|
|
|
|
|
)
|
|
|
|
|
.join('|');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let users = new Array(10) // placeholder
|
|
|
|
|
.fill('16:mat:0')
|
|
|
|
|
.join('|');
|
|
|
|
|
|
|
|
|
|
let songs = ''; // placeholder
|
|
|
|
|
|
|
|
|
|
levelsString = [results, users, songs, levels.length].join('#') +
|
|
|
|
|
`:${offset}:${levelsPerPage}#` +
|
|
|
|
|
hash.hashLevels(foundLevels);
|
|
|
|
|
levelsString = [results, users, songs, levels.length].join('#') +
|
|
|
|
|
`:${offset}:${levelsPerPage}#` +
|
|
|
|
|
hash.hashLevels(foundLevels);
|
|
|
|
|
|
|
|
|
|
res.status(200).send(levelsString);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (let i in handleRequestsAt)
|
|
|
|
|
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', getLevels);
|
|
|
|
|
};
|