diff options
author | Sam X. Chen <sam.xi.chen@gmail.com> | 2019-08-08 16:24:58 -0400 |
---|---|---|
committer | Sam X. Chen <sam.xi.chen@gmail.com> | 2019-08-08 16:24:58 -0400 |
commit | 13a13e8eca67eea4bc8a44dad8a0de52035154ba (patch) | |
tree | c8c2448502d5e1d0f9f50f76c813875d0454ccc2 /models/attachments.js | |
parent | aa6a588376b0961f4a246958d6e9e3f1a020fd1d (diff) | |
download | wekan-13a13e8eca67eea4bc8a44dad8a0de52035154ba.tar.gz wekan-13a13e8eca67eea4bc8a44dad8a0de52035154ba.tar.bz2 wekan-13a13e8eca67eea4bc8a44dad8a0de52035154ba.zip |
Add Features: allowing wekan master to set where the attachments stored on server instead of mongodb
Diffstat (limited to 'models/attachments.js')
-rw-r--r-- | models/attachments.js | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/models/attachments.js b/models/attachments.js index 0616c79f..95265422 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,8 +1,23 @@ -Attachments = new FS.Collection('attachments', { - stores: [ - // XXX Add a new store for cover thumbnails so we don't load big images in - // the general board view - new FS.Store.GridFS('attachments', { +const localFSStore = process.env.ATTACHMENTS_STORE_PATH; +const storeName = 'attachments'; +const defaultStoreOptions = { + beforeWrite: fileObj => { + if (!fileObj.isImage()) { + return { + type: 'application/octet-stream', + }; + } + return {}; + }, +}; +const Store = localFSStore + ? new FS.Store.FileSystem(storeName, { + path: localFSStore, + ...defaultStoreOptions, + }) + : new FS.Store.GridFS(storeName, { + // XXX Add a new store for cover thumbnails so we don't load big images in + // the general board view // If the uploaded document is not an image we need to enforce browser // download instead of execution. This is particularly important for HTML // files that the browser will just execute if we don't serve them with the @@ -12,16 +27,10 @@ Attachments = new FS.Collection('attachments', { // XXX Should we use `beforeWrite` option of CollectionFS instead of // collection-hooks? // We should use `beforeWrite`. - beforeWrite: fileObj => { - if (!fileObj.isImage()) { - return { - type: 'application/octet-stream', - }; - } - return {}; - }, - }), - ], + ...defaultStoreOptions, + }); +Attachments = new FS.Collection('attachments', { + stores: [Store], }); if (Meteor.isServer) { |