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

Added url property to attachments.list

Sotaro KARASAWA 9 лет назад
Родитель
Сommit
f4fe4041fd
2 измененных файлов с 9 добавлено и 2 удалено
  1. 1 1
      lib/models/attachment.js
  2. 8 1
      lib/routes/attachment.js

+ 1 - 1
lib/models/attachment.js

@@ -24,7 +24,7 @@ module.exports = function(crowi) {
   }, {
     toJSON: {
       virtuals: true
-    }
+    },
   });
 
   attachmentSchema.virtual('fileUrl').get(function() {

+ 8 - 1
lib/routes/attachment.js

@@ -63,8 +63,15 @@ module.exports = function(crowi, app) {
 
     Attachment.getListByPageId(id)
     .then(function(attachments) {
+      var config = crowi.getConfig();
+      var baseUrl = (config.crowi['app:url'] || '');
       return res.json(ApiResponse.success({
-        attachments: attachments
+        attachments: attachments.map(at => {
+          var fileUrl = at.fileUrl;
+          at = at.toObject();
+          at.url = baseUrl + fileUrl;
+          return at;
+        })
       }));
     });
   };