From 832d525379fa9b44e9fd67b113162cf8f965b628 Mon Sep 17 00:00:00 2001 From: groenroos Date: Sun, 4 Apr 2021 19:51:44 +0100 Subject: [PATCH] Implement default limit --- core/loadConfig.js | 1 + lib/Storage.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/core/loadConfig.js b/core/loadConfig.js index fc4b055..842c8fb 100644 --- a/core/loadConfig.js +++ b/core/loadConfig.js @@ -36,6 +36,7 @@ module.exports = async function (next) { secret: this.utils.randString(), showError: true, strict: false, + limit: 100, production: 'auto', db: { driver: 'Memory' diff --git a/lib/Storage.js b/lib/Storage.js index 2d552ea..1402d0b 100755 --- a/lib/Storage.js +++ b/lib/Storage.js @@ -497,13 +497,24 @@ module.exports = class Storage { /* Check if we're logged in */ this.app.user.isUserAuthenticatedForRoute(request, response); + /* Parse max limit */ + const limit = (this.config.limit && this.config.limit > 0) ? this.config.limit : false; + /* Parse limit options */ if ('limit' in request.query) { options.limit = Number(request.query.limit) || null; + /* If max limit is set in config, ensure we don't go over it */ + if (limit && options.limit > limit) { + options.limit = limit; + } + if ('skip' in request.query) { options.skip = Number(request.query.skip) || null; } + } else if (limit) { + /* If max limit is set in config, enforce it */ + options.limit = limit; } /* Parse sorting option */