yusueketk 7 лет назад
Родитель
Сommit
d46de3d281

+ 11 - 0
src/server/routes/attachment.js

@@ -47,6 +47,17 @@ module.exports = function(crowi, app) {
       });
   };
 
+  /**
+   * @api {get} /attachments.get get attachments from MongoDB
+   * @apiName getAttachments
+   * @apiGroup Attachment
+   *
+   * @apiParam {String} attachment_path
+   */
+  api.get = function(req, res) {
+    const path = req.body.attachment_path;
+  };
+
   /**
    * @api {get} /attachments.list Get attachments of the page
    * @apiName ListAttachments

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

@@ -208,6 +208,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/bookmarks.remove'   , accessTokenParser , loginRequired(crowi, app) , csrf, bookmark.api.remove);
   app.post('/_api/likes.add'          , accessTokenParser , loginRequired(crowi, app) , csrf, page.api.like);
   app.post('/_api/likes.remove'       , accessTokenParser , loginRequired(crowi, app) , csrf, page.api.unlike);
+  app.get( '/_api/attachments.get'    , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.get);
   app.get( '/_api/attachments.list'   , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.list);
   app.post('/_api/attachments.add'    , uploads.single('file'), accessTokenParser, loginRequired(crowi, app) ,csrf, attachment.api.add);
   app.post('/_api/attachments.remove' , accessTokenParser , loginRequired(crowi, app) , csrf, attachment.api.remove);

+ 11 - 3
src/server/service/file-uploader/gridfs.js

@@ -11,7 +11,7 @@ module.exports = function(crowi) {
 
   // instantiate mongoose-gridfs
   var gridfs = require('mongoose-gridfs')({
-    collection: 'attachments',
+    collection: 'attachmentFiles',
     model: 'AttachmentFile',
     mongooseConnection: mongoose.connection
   });
@@ -41,8 +41,16 @@ module.exports = function(crowi) {
       });
   };
 
-  lib.generateUrl = function(filePath) {
-    return path.posix.join('/uploads', filePath);
+  // lib.findDeliveryFile = async function(fileId, filePath) {
+  // };
+
+  lib.generateUrl = async function(filePath) {
+    crowi.apiGet('/attachments.get', {
+      attachment_path: filePath
+    })
+    .then((res) => {
+      return res;
+    };
   };
 
   return lib;