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

When uploading a file and creating a new page, set pageBody to the markdown of the uploaded page

Shun Miyazawa 3 лет назад
Родитель
Сommit
e3685af8a4
2 измененных файлов с 8 добавлено и 1 удалено
  1. 3 0
      packages/app/src/components/PageEditor.tsx
  2. 5 1
      packages/app/src/server/routes/attachment.js

+ 3 - 0
packages/app/src/components/PageEditor.tsx

@@ -310,6 +310,9 @@ const PageEditor = React.memo((): JSX.Element => {
       if (pageId != null) {
       if (pageId != null) {
         formData.append('page_id', pageId);
         formData.append('page_id', pageId);
       }
       }
+      if (markdownToSave.current != null) {
+        formData.append('page_body', markdownToSave.current);
+      }
 
 
       res = await apiPostForm('/attachments.add', formData);
       res = await apiPostForm('/attachments.add', formData);
       const attachment = res.attachment;
       const attachment = res.attachment;

+ 5 - 1
packages/app/src/server/routes/attachment.js

@@ -1,3 +1,4 @@
+import { pathUtils } from '@growi/core';
 
 
 import { SupportedAction } from '~/interfaces/activity';
 import { SupportedAction } from '~/interfaces/activity';
 import { AttachmentType } from '~/server/interfaces/attachment';
 import { AttachmentType } from '~/server/interfaces/attachment';
@@ -452,6 +453,7 @@ module.exports = function(crowi, app) {
   api.add = async function(req, res) {
   api.add = async function(req, res) {
     let pageId = req.body.page_id || null;
     let pageId = req.body.page_id || null;
     const pagePath = req.body.path || null;
     const pagePath = req.body.path || null;
+    const pageBody = req.body.page_body || null;
     let pageCreated = false;
     let pageCreated = false;
 
 
     // check params
     // check params
@@ -468,10 +470,12 @@ module.exports = function(crowi, app) {
     if (pageId == null) {
     if (pageId == null) {
       logger.debug('Create page before file upload');
       logger.debug('Create page before file upload');
 
 
+      const fixedPageBody = pageBody ?? pathUtils.attachTitleHeader(pagePath);
+
       const isAclEnabled = crowi.aclService.isAclEnabled();
       const isAclEnabled = crowi.aclService.isAclEnabled();
       const grant = isAclEnabled ? Page.GRANT_OWNER : Page.GRANT_PUBLIC;
       const grant = isAclEnabled ? Page.GRANT_OWNER : Page.GRANT_PUBLIC;
 
 
-      page = await crowi.pageService.create(pagePath, `# ${pagePath}`, req.user, { grant });
+      page = await crowi.pageService.create(pagePath, fixedPageBody, req.user, { grant });
       pageCreated = true;
       pageCreated = true;
       pageId = page._id;
       pageId = page._id;
     }
     }