reiji-h 2 лет назад
Родитель
Сommit
c2ca50d4c2

+ 2 - 5
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -309,10 +309,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const uploadHandler = useCallback((files: File[]) => {
     files.forEach(async(file) => {
       try {
-        // eslint-disable-next-line @typescript-eslint/no-explicit-any
-        const { data: resLimit }: any = await apiv3Get('/attachment/limit', {
-          fileSize: file.size,
-        });
+        const { data: resLimit }: any = await apiv3Get('/attachment/limit', { fileSize: file.size });
 
         if (!resLimit.isUploadable) {
           throw new Error(resLimit.errorMessage);
@@ -330,7 +327,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
           formData.append('page_body', codeMirrorEditor?.getDoc() ?? '');
         }
 
-        const resAdd: any = await apiv3PostForm('/attachment/add', formData);
+        const { data: resAdd }: any = await apiv3PostForm('/attachment/add', formData);
 
         const attachment = resAdd.attachment;
         const fileName = attachment.originalName;

+ 6 - 1
apps/app/src/server/routes/apiv3/attachment.js

@@ -1,13 +1,16 @@
 import { ErrorV3 } from '@growi/core/dist/models';
+import multer from 'multer';
 
 import { SupportedAction } from '~/interfaces/activity';
 import { AttachmentType } from '~/server/interfaces/attachment';
 import { Attachment } from '~/server/models';
 import loggerFactory from '~/utils/logger';
 
+import { generateAddActivityMiddleware } from '../../middlewares/add-activity';
 import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
 import { certifySharedPageAttachmentMiddleware } from '../../middlewares/certify-shared-page-attachment';
 
+
 const logger = loggerFactory('growi:routes:apiv3:attachment'); // eslint-disable-line no-unused-vars
 const express = require('express');
 
@@ -30,6 +33,8 @@ module.exports = (crowi) => {
   const Page = crowi.model('Page');
   const User = crowi.model('User');
   const { attachmentService } = crowi;
+  const uploads = multer({ dest: `${crowi.tmpDir}uploads` });
+  const addActivity = generateAddActivityMiddleware(crowi);
 
   const activityEvent = crowi.event('activity');
 
@@ -221,7 +226,7 @@ module.exports = (crowi) => {
    * @apiParam {String} path
    * @apiParam {File} file
    */
-  router.post('/add', accessTokenParser, loginRequired, apiV3FormValidator, async(req, res) => {
+  router.post('/add', uploads.single('file'), accessTokenParser, loginRequired, apiV3FormValidator, addActivity, async(req, res) => {
     const pageId = req.body.page_id || null;
     const pagePath = req.body.path || null;