|
|
@@ -4,9 +4,10 @@ const logger = loggerFactory('growi:routes:apiv3:pages'); // eslint-disable-line
|
|
|
|
|
|
const express = require('express');
|
|
|
|
|
|
-
|
|
|
const router = express.Router();
|
|
|
|
|
|
+const { query } = require('express-validator');
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @swagger
|
|
|
@@ -21,6 +22,20 @@ module.exports = (crowi) => {
|
|
|
|
|
|
const Page = crowi.model('Page');
|
|
|
|
|
|
+ const validator = {
|
|
|
+ displayList: [
|
|
|
+ query('pageLimitationS').custom((value) => {
|
|
|
+ if (value === undefined) {
|
|
|
+ return 10;
|
|
|
+ }
|
|
|
+ if (value > 100) {
|
|
|
+ throw new Error('You should set less than 100 or not to set pageLimitationS.');
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }),
|
|
|
+ ],
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
@@ -84,13 +99,13 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- router.get('/list', accessTokenParser, loginRequired, async(req, res) => {
|
|
|
- const limit = req.query.pageLimitationS || await crowi.configManager.getConfig('crowi', 'customize:showPageLimitationS') || 10;
|
|
|
+ router.get('/list', accessTokenParser, loginRequired, validator.displayList, async(req, res) => {
|
|
|
+ const pageLimitationS = req.query.pageLimitationS || await crowi.configManager.getConfig('crowi', 'customize:showPageLimitationS') || 10;
|
|
|
const { path } = req.query;
|
|
|
const selectedPage = req.query.activePage;
|
|
|
- const offset = (selectedPage - 1) * limit;
|
|
|
+ const offset = (selectedPage - 1) * pageLimitationS;
|
|
|
|
|
|
- const queryOptions = { offset, limit };
|
|
|
+ const queryOptions = { offset, limit: pageLimitationS };
|
|
|
|
|
|
try {
|
|
|
const result = await Page.findListWithDescendants(path, req.user, queryOptions);
|