zahmis пре 5 година
родитељ
комит
e6622513c1

+ 1 - 9
src/server/routes/apiv3/attachment.js

@@ -26,15 +26,7 @@ module.exports = (crowi) => {
   const validator = {
     retrieveAttachments: [
       query('pageId').isMongoId().withMessage('pageId is required'),
-      query('limit').custom((value) => {
-        if (value == null) {
-          return 10;
-        }
-        if (value > 100) {
-          throw new Error('You should set less than 100 or not to set limit.');
-        }
-        return value;
-      }),
+      query('limit').if(value => value != null).isInt({ max: 100 }),
     ],
   };
   /**

+ 1 - 9
src/server/routes/apiv3/bookmarks.js

@@ -145,15 +145,7 @@ module.exports = (crowi) => {
    */
   validator.myBookmarkList = [
     query('page').isInt({ min: 1 }),
-    query('limit').custom((value) => {
-      if (value == null) {
-        return 10;
-      }
-      if (value > 300) {
-        throw new Error('You should set less than 100 or not to set limit.');
-      }
-      return value;
-    }),
+    query('limit').if(value => value != null).isInt({ max: 100 }),
   ];
 
   router.get('/:userId', accessTokenParser, loginRequired, validator.myBookmarkList, apiV3FormValidator, async(req, res) => {

+ 1 - 9
src/server/routes/apiv3/pages.js

@@ -87,15 +87,7 @@ module.exports = (crowi) => {
   });
 
   validator.displayList = [
-    query('limit').custom((value) => {
-      if (value == null) {
-        return 10;
-      }
-      if (value > 100) {
-        throw new Error('You should set less than 100 or not to set limit.');
-      }
-      return value;
-    }),
+    query('limit').if(value => value != null).isInt({ max: 100 }),
   ];
 
   router.get('/list', accessTokenParser, loginRequired, validator.displayList, apiV3FormValidator, async(req, res) => {

+ 2 - 9
src/server/routes/apiv3/revisions.js

@@ -70,15 +70,8 @@ module.exports = (crowi) => {
     retrieveRevisions: [
       query('pageId').isMongoId().withMessage('pageId is required'),
       query('page').isInt({ min: 0 }).withMessage('page must be int'),
-      query('limit').custom((value) => {
-        if (value == null) {
-          return 10;
-        }
-        if (value > 100) {
-          throw new Error('You should set less than 100 or not to set limit.');
-        }
-        return value;
-      }),
+      query('limit').if(value => value != null).isInt({ max: 100 }),
+
     ],
     retrieveRevisionById: [
       query('pageId').isMongoId().withMessage('pageId is required'),

+ 1 - 9
src/server/routes/apiv3/users.js

@@ -106,15 +106,7 @@ module.exports = (crowi) => {
   ];
 
   validator.recentCreatedByUser = [
-    query('limit').custom((value) => {
-      if (value == null) {
-        return 10;
-      }
-      if (value > 300) {
-        throw new Error('You should set less than 100 or not to set limit.');
-      }
-      return value;
-    }),
+    query('limit').if(value => value != null).isInt({ max: 100 }),
   ];
 
   /**