Просмотр исходного кода

Merge pull request #2464 from weseek/feat/define-archive-model

Feat/create archive model
yusuketk 5 лет назад
Родитель
Сommit
43330be9b0

+ 4 - 4
src/client/js/components/ArchiveCreateModal.jsx

@@ -14,7 +14,7 @@ const ArchiveCreateModal = (props) => {
   const [isCommentDownload, setIsCommentDownload] = useState(false);
   const [isAttachmentFileDownload, setIsAttachmentFileDownload] = useState(false);
   const [isSubordinatedPageDownload, setIsSubordinatedPageDownload] = useState(false);
-  const [fileType, setFileType] = useState('markDown');
+  const [fileType, setFileType] = useState('markdown');
   const [hierarchyType, setHierarchyType] = useState('allSubordinatedPage');
   const [hierarchyValue, setHierarchyValue] = useState(1);
 
@@ -57,6 +57,7 @@ const ArchiveCreateModal = (props) => {
 
     try {
       await appContainer.apiv3Post('/page/archive', {
+        rootPagePath: props.path,
         isCommentDownload,
         isAttachmentFileDownload,
         isSubordinatedPageDownload,
@@ -94,9 +95,9 @@ const ArchiveCreateModal = (props) => {
               id="customRadio1"
               name="isFileType"
               value="customRadio1"
-              checked={fileType === 'markDown'}
+              checked={fileType === 'markdown'}
               onChange={() => {
-                handleChangeFileType('markDown');
+                handleChangeFileType('markdown');
               }}
             />
             <label className="custom-control-label" htmlFor="customRadio1">
@@ -234,5 +235,4 @@ ArchiveCreateModal.propTypes = {
   path: PropTypes.string.isRequired,
 };
 
-
 export default withTranslation()(ArchiveCreateModalWrapper);

+ 1 - 0
src/server/models/index.js

@@ -1,6 +1,7 @@
 module.exports = {
   Config: require('./config'),
   Page: require('./page'),
+  PageArchive: require('./page-archive'),
   PageTagRelation: require('./page-tag-relation'),
   User: require('./user'),
   ExternalAccount: require('./external-account'),

+ 22 - 0
src/server/models/page-archive.js

@@ -0,0 +1,22 @@
+module.exports = function(crowi) {
+  const mongoose = require('mongoose');
+  const ObjectId = mongoose.Schema.Types.ObjectId;
+
+  const pageArchiveSchema = new mongoose.Schema({
+    owner: {
+      type: ObjectId,
+      ref: 'User',
+      index: true,
+      required: true,
+    },
+    rootPagePath: { type: String, required: true },
+    fileType: { type: String, enum: ['pdf', 'markdown'], required: true },
+    numOfPages: { type: Number, required: true },
+    hasComment: { type: Boolean, required: true },
+    hasAttachment: { type: Boolean, required: true },
+  }, {
+    timestamps: true,
+  });
+
+  return mongoose.model('PageArchive', pageArchiveSchema);
+};

+ 56 - 12
src/server/routes/apiv3/page.js

@@ -126,10 +126,11 @@ module.exports = (crowi) => {
     ],
 
     archive: [
+      body('rootPagePath').isString(),
       body('isCommentDownload').isBoolean(),
       body('isAttachmentFileDownload').isBoolean(),
       body('isSubordinatedPageDownload').isBoolean(),
-      body('fileType').isString().isIn(['pdf', 'markDown']),
+      body('fileType').isString().isIn(['pdf', 'markdown']),
       body('hierarchyType').isString().isIn(['allSubordinatedPage', 'decideHierarchy']),
       body('hierarchyValue').isNumeric(),
     ],
@@ -191,26 +192,69 @@ module.exports = (crowi) => {
     return res.apiv3({ result });
   });
 
+  /**
+   * @swagger
+   *
+   *    /page/archive:
+   *      post:
+   *        tags: [Page]
+   *        summary: /page/archive
+   *        description: create page archive
+   *        requestBody:
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  rootPagePath:
+   *                    type: string
+   *                    description: path of the root page
+   *                  isCommentDownload:
+   *                    type: boolean
+   *                    description: whether archive data contains comments
+   *                  isAttachmentFileDownload:
+   *                    type: boolean
+   *                    description: whether archive data contains attachments
+   *                  isSubordinatedPageDownload:
+   *                    type: boolean
+   *                    description: whether archive data children pages
+   *                  fileType:
+   *                    type: string
+   *                    description: file type of archive data(.md, .pdf)
+   *                  hierarchyType:
+   *                    type: string
+   *                    description: method of select children pages archive data contains('allSubordinatedPage', 'decideHierarchy')
+   *                  hierarchyValue:
+   *                    type: number
+   *                    description: depth of hierarchy(use when hierarchyType is 'decideHierarchy')
+   *        responses:
+   *          200:
+   *            description: create page archive
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  $ref: '#/components/schemas/Page'
+   */
   router.post('/archive', accessTokenParser, loginRequired, csrf, validator.archive, apiV3FormValidator, async(req, res) => {
+    const PageArchive = crowi.model('PageArchive');
 
     const {
+      rootPagePath,
       isCommentDownload,
       isAttachmentFileDownload,
-      isSubordinatedPageDownload,
       fileType,
-      hierarchyType,
-      hierarchyValue,
     } = req.body;
+    const owner = req.user._id;
 
+    const numOfPages = 1; // TODO 最終的にzipファイルに取り込むページ数を入れる
 
-    console.log(isCommentDownload);
-    console.log(isAttachmentFileDownload);
-    console.log(fileType);
-    console.log(isSubordinatedPageDownload);
-    console.log(hierarchyType);
-    console.log(hierarchyValue);
-
-    return res.apiv3({});
+    await PageArchive.create({
+      owner,
+      fileType,
+      rootPagePath,
+      numOfPages,
+      hasComment: isCommentDownload,
+      hasAttachment: isAttachmentFileDownload,
+    });
   });
 
   return router;