瀏覽代碼

Fix client handling

Sotaro KARASAWA 9 年之前
父節點
當前提交
8024fb3769
共有 3 個文件被更改,包括 16 次插入5 次删除
  1. 1 1
      lib/models/attachment.js
  2. 12 2
      lib/routes/attachment.js
  3. 3 2
      local_modules/crowi-fileupload-aws/index.js

+ 1 - 1
lib/models/attachment.js

@@ -28,7 +28,7 @@ module.exports = function(crowi) {
   });
 
   attachmentSchema.virtual('fileUrl').get(function() {
-    return fileUploader.generateUrl(this.filePath);
+    return `/files/${this._id}`;
   });
 
   attachmentSchema.statics.findById = function(id) {

+ 12 - 2
lib/routes/attachment.js

@@ -33,7 +33,9 @@ module.exports = function(crowi, app) {
           },
         };
 
+        debug(deliveryFile.fileName);
         if (deliveryFile.fileName.match(/^\/uploads/)) {
+          debug('Using loacal file module, just redirecting.')
           return res.redirect(deliveryFile.fileName);
         } else {
           return res.sendFile(deliveryFile.fileName, deliveryFile.options);
@@ -123,11 +125,19 @@ module.exports = function(crowi, app) {
           // TODO size
           return Attachment.create(id, req.user, filePath, originalName, fileName, fileType, fileSize);
         }).then(function(data) {
-          var imageUrl = fileUploader.generateUrl(data.filePath);
+          var fileUrl = data.fileUrl;
+          var config = crowi.getConfig();
+
+          // isLocalUrl??
+          if (!fileUrl.match(/^https?/)) {
+            fileUrl = (config.crowi['app:url'] || '') + fileUrl;
+          }
+
           var result = {
             page: page.toObject(),
             attachment: data.toObject(),
-            filename: imageUrl,
+            url: fileUrl,
+            filename: fileUrl, // this is for inline-attachemnets plugin http://inlineattachment.readthedocs.io/en/latest/pages/configuration.html
             pageCreated: pageCreated,
           };
 

+ 3 - 2
local_modules/crowi-fileupload-aws/index.js

@@ -74,8 +74,9 @@ module.exports = function(crowi) {
       var loader = require('https');
 
       var fileStream = fs.createWriteStream(cacheFile);
-      debug('Load attachement file into local cache file', attachment.fileUrl, cacheFile);
-      var request = loader.get(attachment.fileUrl, function(response) {
+      var fileUrl = lib.generateUrl(attachement.filePath);
+      debug('Load attachement file into local cache file', fileUrl, cacheFile);
+      var request = loader.get(fileUrl, function(response) {
         response.pipe(fileStream, { end: false });
         response.on('end', () => {
           fileStream.end();