From 13a13e8eca67eea4bc8a44dad8a0de52035154ba Mon Sep 17 00:00:00 2001 From: "Sam X. Chen" Date: Thu, 8 Aug 2019 16:24:58 -0400 Subject: Add Features: allowing wekan master to set where the attachments stored on server instead of mongodb --- models/attachments.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'models/attachments.js') 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) { -- cgit v1.2.3-1-g7c22