advanced searching (still a wip)
This commit is contained in:
parent
8d98eb7a00
commit
e0f9b3dfeb
|
@ -4,15 +4,50 @@ module.exports = (app, db) : void => {
|
||||||
app.post('/aa/database/getGJLevels21.php', async (req, res) => {
|
app.post('/aa/database/getGJLevels21.php', async (req, res) => {
|
||||||
let levelsString = '';
|
let levelsString = '';
|
||||||
|
|
||||||
const levels = await db.collection('levels').find({
|
let searchQuery: any = {}; // fuck you typescript, i have to use any or else it screams
|
||||||
$or: [{id: Number(req.body.str)}, {name: {$regex: `${req.body.str}`}}]
|
|
||||||
|
if (req.body.featured) searchQuery.featured = 1;
|
||||||
|
if (req.body.epic) searchQuery.epic = 1;
|
||||||
|
if (req.body.coins) searchQuery.coins = 1;
|
||||||
|
if (req.body.twoPlayer) searchQuery.twoPlayer = 1;
|
||||||
|
if (req.body.star) searchQuery.stars = {$gt: 0};
|
||||||
|
if (req.body.original) searchQuery.original = 1;
|
||||||
|
|
||||||
|
if (req.body.diff != '-') {
|
||||||
|
// if the client requests -1, -2 or -3 then it cant request any other difficulties
|
||||||
|
if (req.body.diff == '-1') { // NA levels
|
||||||
|
searchQuery.diff = 0;
|
||||||
|
} else if(req.body.diff == '-2') { // demons
|
||||||
|
searchQuery.diff = {$gte: 60};
|
||||||
|
// TODO: implement req.body.demonDiff stuff
|
||||||
|
} else if(req.body.diff == '-3') { // auto
|
||||||
|
searchQuery.auto = 1;
|
||||||
|
} else {
|
||||||
|
searchQuery.$or = req.body.diff
|
||||||
|
.split(',') // multiple diffs
|
||||||
|
.map(d => {
|
||||||
|
return {diff: Number(d) * 10};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const levels = await db.collection('levels').find(
|
||||||
|
{
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
$or: [
|
||||||
|
{id: Number(req.body.str)},
|
||||||
|
{name: {$regex: `${req.body.str}`}}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
searchQuery
|
||||||
|
]
|
||||||
})
|
})
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
// TODO: searching
|
|
||||||
let results = levels
|
let results = levels
|
||||||
.map(l =>
|
.map(l =>
|
||||||
`1:${l.id}:2:${l.name}:5:0:6:16:8:10:9:${l.diff}:10:${l.downloads}:12:1:13:21:14:${l.likes}:17:0:43:0:25:0:18:${l.stars}:19:0:42:0:45:10:3:${l.description}:15:1:30:0:31:0:37:0:38:0:39:0:46:1:47:2:40:0:35:0`
|
`1:${l.id}:2:${l.name}:5:0:6:16:8:10:9:${l.diff}:10:${l.downloads}:12:1:13:21:14:${l.likes}:17:0:43:0:25:${l.auto ? '1' : '0'}:18:${l.stars}:19:0:42:0:45:10:3:${l.description}:15:1:30:0:31:0:37:0:38:0:39:0:46:1:47:2:40:0:35:0`
|
||||||
)
|
)
|
||||||
.join('|');
|
.join('|');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue