make levelsPerPage a constant
This commit is contained in:
parent
c54a19abb4
commit
7c25e98016
|
@ -1,5 +1,7 @@
|
||||||
import * as hash from './hash';
|
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 => {
|
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 = '';
|
||||||
|
@ -86,10 +88,10 @@ module.exports = (app, db) : void => {
|
||||||
levels.filter(() => false);
|
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
|
const foundLevels = levels
|
||||||
.slice(offset, (Number(req.body.page) + 1) * 10 - 1);
|
.slice(offset, (Number(req.body.page) + 1) * levelsPerPage - 1);
|
||||||
|
|
||||||
let results = foundLevels
|
let results = foundLevels
|
||||||
.map(l =>
|
.map(l =>
|
||||||
|
@ -104,7 +106,7 @@ module.exports = (app, db) : void => {
|
||||||
let songs = ''; // placeholder
|
let songs = ''; // placeholder
|
||||||
|
|
||||||
levelsString = [results, users, songs, levels.length].join('#') +
|
levelsString = [results, users, songs, levels.length].join('#') +
|
||||||
`:${offset}:10#` +
|
`:${offset}:${levelsPerPage}#` +
|
||||||
hash.hashLevels(foundLevels);
|
hash.hashLevels(foundLevels);
|
||||||
|
|
||||||
res.status(200).send(levelsString);
|
res.status(200).send(levelsString);
|
||||||
|
|
Loading…
Reference in New Issue