make levelsPerPage a constant

This commit is contained in:
oatmealine 2020-01-25 17:25:38 +03:00
parent c54a19abb4
commit 7c25e98016
No known key found for this signature in database
GPG Key ID: C4CB49CFAD721145
1 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,7 @@
import * as hash from './hash';
const levelsPerPage = 10; // should be kept at 10, increasing/decreasing may lead to unforseeable consequences
module.exports = (app, db) : void => {
app.post('/aa/database/getGJLevels21.php', async (req, res) => {
let levelsString = '';
@ -86,10 +88,10 @@ module.exports = (app, db) : void => {
levels.filter(() => false);
}
let offset = Math.max(Number(req.body.page) * 10 - 1, 0);
let offset = Math.max(Number(req.body.page) * levelsPerPage - 1, 0);
const foundLevels = levels
.slice(offset, (Number(req.body.page) + 1) * 10 - 1);
.slice(offset, (Number(req.body.page) + 1) * levelsPerPage - 1);
let results = foundLevels
.map(l =>
@ -104,7 +106,7 @@ module.exports = (app, db) : void => {
let songs = ''; // placeholder
levelsString = [results, users, songs, levels.length].join('#') +
`:${offset}:10#` +
`:${offset}:${levelsPerPage}#` +
hash.hashLevels(foundLevels);
res.status(200).send(levelsString);