Преглед изворни кода

Add Features: allowing wekan master to set where the attachments stored on server instead of mongodb

Sam X. Chen пре 5 година
родитељ
комит
13a13e8eca
5 измењених фајлова са 33 додато и 15 уклоњено
  1. 1 0
      .meteor/packages
  2. 1 0
      .meteor/versions
  3. 3 0
      client/components/cards/attachments.js
  4. 24 15
      models/attachments.js
  5. 4 0
      snap-src/bin/config

+ 1 - 0
.meteor/packages

@@ -95,3 +95,4 @@ wekan-markdown
 konecty:mongo-counter
 percolate:synced-cron
 easylogic:summernote
+cfs:filesystem

+ 1 - 0
.meteor/versions

@@ -30,6 +30,7 @@ cfs:collection@0.5.5
 cfs:collection-filters@0.2.4
 cfs:data-man@0.0.6
 cfs:file@0.1.17
+cfs:filesystem@0.1.2
 cfs:gridfs@0.0.34
 cfs:http-methods@0.0.32
 cfs:http-publish@0.0.13

+ 3 - 0
client/components/cards/attachments.js

@@ -66,6 +66,9 @@ Template.cardAttachmentsPopup.events({
         file.cardId = card._id;
       }
       file.userId = Meteor.userId();
+      if (file.original) {
+        file.original.name = f.name;
+      }
       const attachment = Attachments.insert(file);
 
       if (attachment && attachment._id && attachment.isImage()) {

+ 24 - 15
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) {

+ 4 - 0
snap-src/bin/config

@@ -88,6 +88,10 @@ DESCRIPTION_ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW="Accounts lockout unkn
 DEFAULT_ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW="15"
 KEY_ACCOUNTS_LOCKOUT_UNKNOWN_USERS_FAILURE_WINDOW="accounts-lockout-unknown-users-failure-window"
 
+DESCRIPTION_ATTACHMENTS_STORE_PATH="Allow wekan ower to specify where uploaded files to store on the server instead of the mongodb"
+DEFAULT_ATTACHMENTS_STORE_PATH=""
+KEY_ATTACHMENTS_STORE_PATH="attachments-store-path"
+
 DESCRIPTION_MAX_IMAGE_PIXEL="Max image pixel: Allow to shrink attached/pasted image https://github.com/wekan/wekan/pull/2544"
 DEFAULT_MAX_IMAGE_PIXEL=""
 KEY_MAX_IMAGE_PIXEL="max-image-pixel"