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

generateUrl of gridfs.js return an endpoint

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

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

@@ -52,7 +52,6 @@ module.exports = function(crowi) {
         }
         }
         return resolve(data);
         return resolve(data);
       });
       });
-
     });
     });
   };
   };
 
 

+ 8 - 4
src/server/routes/attachment.js

@@ -66,11 +66,15 @@ module.exports = function(crowi, app) {
    *
    *
    * @apiParam {String} attachment_path
    * @apiParam {String} attachment_path
    */
    */
-  api.get = function(req, res) {
-    const filePath = "attachment/5ba1b857275c752f20b7204b/1495bb6b10a2b062ac9cc9bde306957a.png";
-    const id = AttachmentFile.find({filename: filePath}, function(file) {
-      return file._id;
+  api.getMongoFile = async function(req, res) {
+    const filePath = req.filePath;
+    const file = await AttachmentFile.find({filename: filePath}, function(err, file) {
+      if (err) {
+        throw new Error(err);
+      }
     });
     });
+    const id = file[0].id;
+
 
 
     const stream = AttachmentFile.readById(id);
     const stream = AttachmentFile.readById(id);
     stream.on('error', function(error) {
     stream.on('error', function(error) {

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

@@ -208,7 +208,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/bookmarks.remove'   , accessTokenParser , loginRequired(crowi, app) , csrf, bookmark.api.remove);
   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.add'          , accessTokenParser , loginRequired(crowi, app) , csrf, page.api.like);
   app.post('/_api/likes.remove'       , accessTokenParser , loginRequired(crowi, app) , csrf, page.api.unlike);
   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.getMongo'  , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.getMongoFile);
   app.get( '/_api/attachments.list'   , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.list);
   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.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);
   app.post('/_api/attachments.remove' , accessTokenParser , loginRequired(crowi, app) , csrf, attachment.api.remove);

+ 1 - 1
src/server/service/file-uploader/gridfs.js

@@ -99,7 +99,7 @@ module.exports = function(crowi) {
 
 
 
 
   lib.generateUrl = function(filePath) {
   lib.generateUrl = function(filePath) {
-    const url = '';
+    const url = 'http://localhost:3000/_api/attachments.getMongo';
     return url;
     return url;
   };
   };