zahmis 5 лет назад
Родитель
Сommit
3834b7e8f4
2 измененных файлов с 13 добавлено и 12 удалено
  1. 6 6
      src/client/js/components/PageAttachment.jsx
  2. 7 6
      src/server/routes/apiv3/attachment.js

+ 6 - 6
src/client/js/components/PageAttachment.jsx

@@ -15,11 +15,10 @@ class PageAttachment extends React.Component {
   constructor(props) {
     super(props);
 
-    const { appContainer } = this.props;
     this.state = {
       activePage: 1,
-      limit: appContainer.getConfig().pageLimitationS || 10,
       totalAttachments: 0,
+      limit: Infinity,
       attachments: [],
       inUse: {},
       attachmentToDelete: null,
@@ -35,27 +34,27 @@ class PageAttachment extends React.Component {
 
   async handlePage(selectedPage) {
     const { pageId } = this.props.pageContainer.state;
-    const { limit } = this.state;
-    const offset = (selectedPage - 1) * limit;
+    // const offset = (selectedPage - 1) * limit;
     const activePage = selectedPage;
 
     if (!pageId) { return }
 
     const res = await this.props.appContainer.apiv3Get('/attachment/list', {
-      pageId, limit, offset,
+      pageId, /* limit, offset, */
     });
     const attachments = res.data.paginateResult.docs;
     const totalAttachments = res.data.paginateResult.totalDocs;
+    const pagingLimit = res.data.paginateResult.limit;
 
     const inUse = {};
 
     for (const attachment of attachments) {
       inUse[attachment._id] = this.checkIfFileInUse(attachment);
     }
-
     this.setState({
       activePage,
       totalAttachments,
+      limit: pagingLimit,
       attachments,
       inUse,
     });
@@ -115,6 +114,7 @@ class PageAttachment extends React.Component {
 
 
   render() {
+    // console.log(this.state.limit);
     const { t } = this.props;
     if (this.state.attachments.length === 0) {
       return t('No_attachments_yet');

+ 7 - 6
src/server/routes/apiv3/attachment.js

@@ -27,8 +27,8 @@ module.exports = (crowi) => {
   const validator = {
     retrieveAttachments: [
       query('pageId').isMongoId().withMessage('pageId is required'),
-      query('limit').isInt({ min: 1 }),
-      query('offset').isInt({ min: 0 }),
+      // query('pagingLimit').isInt({ min: 1 }).isInt({ max: 1000 }), // temp data
+      // query('offset').isInt({ min: 0 }),
     ],
   };
   /**
@@ -50,8 +50,7 @@ module.exports = (crowi) => {
    *              type: string
    */
   router.get('/list', accessTokenParser, loginRequired, validator.retrieveAttachments, apiV3FormValidator, async(req, res) => {
-    const offset = +req.query.offset || 0;
-    const limit = +req.query.limit || 30;
+    // const offset = +req.query.offset || 0;
 
     try {
       const pageId = req.query.pageId;
@@ -62,11 +61,13 @@ module.exports = (crowi) => {
         return res.apiv3Err(new ErrorV3(msg, 'attachment-list-failed'), 403);
       }
 
+      // directly get paging-size from db. not to delivery from client side.
+      const pageLimitationS = await crowi.configManager.getConfig('crowi', 'customize:showPageLimitationS') || 10;
       const paginateResult = await Attachment.paginate(
         { page: pageId },
         {
-          limit,
-          offset,
+          limit: pageLimitationS,
+          // offset,
           populate: {
             path: 'creator',
             select: User.USER_PUBLIC_FIELDS,