Explorar el Código

move to service

yusuketk hace 5 años
padre
commit
ad1d3d0121
Se han modificado 2 ficheros con 12 adiciones y 9 borrados
  1. 6 3
      src/server/routes/apiv3/page.js
  2. 6 6
      src/server/service/export.js

+ 6 - 3
src/server/routes/apiv3/page.js

@@ -231,10 +231,13 @@ module.exports = (crowi) => {
       const Revision = crowi.model('Revision');
       const Revision = crowi.model('Revision');
       const revision = await Revision.findById(revisionIdForFind);
       const revision = await Revision.findById(revisionIdForFind);
 
 
-      const markdown = revision.body;
+      const fileName = revisionId;
+      const stream = exportService.getReadStreamFromRevision(revision);
 
 
-      const fileName = pageId != null ? pageId : revisionId;
-      return exportService.getReadStreamAsFileFromString(res, markdown, fileName, format);
+      res.set({
+        'Content-Disposition': `attachment;filename*=UTF-8''${fileName}.${format}`,
+      });
+      return stream.pipe(res);
     }
     }
     catch (err) {
     catch (err) {
       logger.error('Failed to get markdown', err);
       logger.error('Failed to get markdown', err);

+ 6 - 6
src/server/service/export.js

@@ -350,16 +350,16 @@ class ExportService {
     return zipFile;
     return zipFile;
   }
   }
 
 
-  getReadStreamAsFileFromString(res, str, fileName, format) {
+  getReadStreamFromRevision(revision) {
+    const markdown = revision.body;
+
     const Readable = require('stream').Readable;
     const Readable = require('stream').Readable;
     const readable = new Readable();
     const readable = new Readable();
     readable._read = () => {};
     readable._read = () => {};
-    readable.push(str);
+    readable.push(markdown);
     readable.push(null);
     readable.push(null);
-    res.set({
-      'Content-Disposition': `attachment;filename*=UTF-8''${fileName}.${format}`,
-    });
-    return readable.pipe(res);
+
+    return readable;
   }
   }
 
 
 }
 }