From 7c25e98016987755c74a07a216d8bfe5d9d5a473 Mon Sep 17 00:00:00 2001 From: oatmealine Date: Sat, 25 Jan 2020 17:25:38 +0300 Subject: [PATCH] make levelsPerPage a constant --- src/getGJLevels21.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/getGJLevels21.ts b/src/getGJLevels21.ts index b464a51..296bee3 100644 --- a/src/getGJLevels21.ts +++ b/src/getGJLevels21.ts @@ -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);