search pages

This commit is contained in:
oatmealine 2020-01-25 16:00:33 +03:00
parent e35272b282
commit 1c56286cd8
No known key found for this signature in database
GPG Key ID: C4CB49CFAD721145
1 changed files with 10 additions and 5 deletions

View File

@ -37,8 +37,6 @@ module.exports = (app, db) : void => {
} }
} }
console.log(searchQuery);
const levels = await db.collection('levels').find( const levels = await db.collection('levels').find(
{ {
$and: [ $and: [
@ -53,19 +51,26 @@ module.exports = (app, db) : void => {
}) })
.toArray(); .toArray();
let results = levels let offset = Math.max(Number(req.body.page) * 10 - 1, 0);
const foundLevels = levels
.slice(offset, (Number(req.body.page) + 1) * 10 - 1);
let results = foundLevels
.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:${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` `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('|');
let users = new Array(levels.length) // placeholder let users = new Array(10) // placeholder
.fill('16:mat:0') .fill('16:mat:0')
.join('|'); .join('|');
let songs = ''; // placeholder let songs = ''; // placeholder
levelsString = [results, users, songs, levels.length].join('#') + ':0:10#' + hash.hashLevels(levels); levelsString = [results, users, songs, levels.length].join('#') +
`:${offset}:10#` +
hash.hashLevels(foundLevels);
res.status(200).send(levelsString); res.status(200).send(levelsString);
}); });