zahmis 5 ani în urmă
părinte
comite
8a0316d995

+ 0 - 4
src/client/js/components/PageAttachment.jsx

@@ -13,15 +13,12 @@ class PageAttachment extends React.Component {
   constructor(props) {
     super(props);
 
-    const { appContainer } = this.props;
     this.state = {
       attachments: [],
       inUse: {},
       attachmentToDelete: null,
       deleting: false,
       deleteError: '',
-      limit: appContainer.getConfig().recentCreatedLimit,
-      offset: 0,
     };
 
     this.onAttachmentDeleteClicked = this.onAttachmentDeleteClicked.bind(this);
@@ -30,7 +27,6 @@ class PageAttachment extends React.Component {
 
   async componentDidMount() {
     const { pageId } = this.props.pageContainer.state;
-    const { limit, offset } = this.state;
 
     if (!pageId) {
       return;

+ 9 - 0
src/server/models/attachment.js

@@ -65,5 +65,14 @@ module.exports = function(crowi) {
     return attachment;
   };
 
+  attachmentSchema.static.paginateAttachments = function() {
+    const query = {};
+    const options = Object.assign({ populate: 'user' });
+    if (options.page == null) {
+      options.page = 1;
+    }
+    return this.paginate(query, options);
+  };
+
   return mongoose.model('Attachment', attachmentSchema);
 };

+ 4 - 2
src/server/routes/apiv3/attachment.js

@@ -39,8 +39,8 @@ module.exports = (crowi) => {
    *              type: string
    */
   router.get('/list', accessTokenParser, loginRequired, async(req, res) => {
-    const limit = +req.query.limit || 30;
     const offset = +req.query.offset || 0;
+    const limit = +req.query.limit || 30;
     const queryOptions = { offset, limit };
 
     try {
@@ -58,7 +58,9 @@ module.exports = (crowi) => {
 
       console.log(pagination);
 
-      return res.apiv3({ attachments });
+      const result = { attachments, pagination };
+
+      return res.apiv3({ result });
 
     }
     catch (err) {