Преглед изворни кода

Merge pull request #2758 from weseek/add-validation-for-attachment

Add validation for attachment
Yuki Takei пре 5 година
родитељ
комит
8ae3895cb4
1 измењених фајлова са 11 додато и 1 уклоњено
  1. 11 1
      src/server/routes/apiv3/attachment.js

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

@@ -5,6 +5,7 @@ const logger = loggerFactory('growi:routes:apiv3:attachment'); // eslint-disable
 const express = require('express');
 const express = require('express');
 
 
 const router = express.Router();
 const router = express.Router();
+const { query } = require('express-validator');
 
 
 const ErrorV3 = require('../../models/vo/error-apiv3');
 const ErrorV3 = require('../../models/vo/error-apiv3');
 
 
@@ -19,7 +20,16 @@ module.exports = (crowi) => {
   const loginRequired = require('../../middlewares/login-required')(crowi);
   const loginRequired = require('../../middlewares/login-required')(crowi);
   const Page = crowi.model('Page');
   const Page = crowi.model('Page');
   const Attachment = crowi.model('Attachment');
   const Attachment = crowi.model('Attachment');
+  const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
 
 
+
+  const validator = {
+    retrieveAttachments: [
+      query('pageId').isMongoId().withMessage('pageId is required'),
+      query('limit').isInt({ min: 1 }),
+      query('offset').isInt({ min: 0 }),
+    ],
+  };
   /**
   /**
    * @swagger
    * @swagger
    *
    *
@@ -38,7 +48,7 @@ module.exports = (crowi) => {
    *            schema:
    *            schema:
    *              type: string
    *              type: string
    */
    */
-  router.get('/list', accessTokenParser, loginRequired, async(req, res) => {
+  router.get('/list', accessTokenParser, loginRequired, validator.retrieveAttachments, apiV3FormValidator, async(req, res) => {
     const offset = +req.query.offset || 0;
     const offset = +req.query.offset || 0;
     const limit = +req.query.limit || 30;
     const limit = +req.query.limit || 30;
     const queryOptions = { offset, limit };
     const queryOptions = { offset, limit };