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

WIP: refactor attachment

re-impl obsoletedGetForMongoDB
Yuki Takei 7 лет назад
Родитель
Сommit
5d4bdd272c
1 измененных файлов с 10 добавлено и 6 удалено
  1. 10 6
      src/server/routes/attachment.js

+ 10 - 6
src/server/routes/attachment.js

@@ -91,17 +91,21 @@ module.exports = function(crowi, app) {
     if (process.env.FILE_UPLOAD !== 'mongodb') {
     if (process.env.FILE_UPLOAD !== 'mongodb') {
       return res.status(400);
       return res.status(400);
     }
     }
+
     const pageId = req.params.pageId;
     const pageId = req.params.pageId;
     const fileName = req.params.fileName;
     const fileName = req.params.fileName;
     const filePath = `attachment/${pageId}/${fileName}`;
     const filePath = `attachment/${pageId}/${fileName}`;
-    try {
-      const fileData = await fileUploader.getFileData(filePath);
-      res.set('Content-Type', fileData.contentType);
-      return res.send(ApiResponse.success(fileData.data));
-    }
-    catch (e) {
+
+    const attachment = await Attachment.findOne({ filePath });
+
+    if (attachment == null) {
       return res.json(ApiResponse.error('attachment not found'));
       return res.json(ApiResponse.error('attachment not found'));
     }
     }
+
+    req.params.id = attachment._id.toString();
+
+    // delegate to 'get' method
+    return api.get(req, res);
   };
   };
 
 
   /**
   /**