summaryrefslogtreecommitdiffstats
path: root/models/attachments.js
diff options
context:
space:
mode:
authorRomulus Urakagi Tsai <urakagi@gmail.com>2019-11-18 01:47:26 +0000
committerRomulus Urakagi Tsai <urakagi@gmail.com>2019-11-18 01:47:26 +0000
commit05c53ca01d71a01a608c9ae345475abd67c9939b (patch)
treea4ec2b021d87ece452709ff0b8dd3eaa794c44fd /models/attachments.js
parent9fd14f7ecb593d3debf5adff8f6c61adb0c3feca (diff)
downloadwekan-05c53ca01d71a01a608c9ae345475abd67c9939b.tar.gz
wekan-05c53ca01d71a01a608c9ae345475abd67c9939b.tar.bz2
wekan-05c53ca01d71a01a608c9ae345475abd67c9939b.zip
Trying to upload an attachment with Meteor-Files
Diffstat (limited to 'models/attachments.js')
-rw-r--r--models/attachments.js47
1 files changed, 39 insertions, 8 deletions
diff --git a/models/attachments.js b/models/attachments.js
index 9b8ec04f..fd03e6d2 100644
--- a/models/attachments.js
+++ b/models/attachments.js
@@ -1,3 +1,29 @@
+import { FilesCollection } from 'meteor/ostrio:files';
+
+Attachments = new FilesCollection({
+ storagePath: storagePath(),
+ debug: true, // FIXME: Remove debug mode
+ collectionName: 'attachments2',
+ allowClientCode: false, // Disallow remove files from Client
+});
+
+if (Meteor.isServer) {
+ Meteor.startup(() => {
+ Attachments.collection._ensureIndex({ cardId: 1 });
+ });
+
+ // TODO: Permission related
+ // TODO: Add Activity update
+ // TODO: publish and subscribe
+// Meteor.publish('files.attachments.all', function () {
+// return Attachments.find().cursor;
+// });
+} else {
+// Meteor.subscribe('files.attachments.all');
+}
+
+// ---------- Deprecated fallback ---------- //
+
const localFSStore = process.env.ATTACHMENTS_STORE_PATH;
const storeName = 'attachments';
const defaultStoreOptions = {
@@ -171,16 +197,16 @@ if (localFSStore) {
...defaultStoreOptions,
});
}
-Attachments = new FS.Collection('attachments', {
+DeprecatedAttachs = new FS.Collection('attachments', {
stores: [store],
});
if (Meteor.isServer) {
Meteor.startup(() => {
- Attachments.files._ensureIndex({ cardId: 1 });
+ DeprecatedAttachs.files._ensureIndex({ cardId: 1 });
});
- Attachments.allow({
+ DeprecatedAttachs.allow({
insert(userId, doc) {
return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
},
@@ -206,10 +232,10 @@ if (Meteor.isServer) {
});
}
-// XXX Enforce a schema for the Attachments CollectionFS
+// XXX Enforce a schema for the DeprecatedAttachs CollectionFS
if (Meteor.isServer) {
- Attachments.files.after.insert((userId, doc) => {
+ DeprecatedAttachs.files.after.insert((userId, doc) => {
// If the attachment doesn't have a source field
// or its source is different than import
if (!doc.source || doc.source !== 'import') {
@@ -227,7 +253,7 @@ if (Meteor.isServer) {
} else {
// Don't add activity about adding the attachment as the activity
// be imported and delete source field
- Attachments.update(
+ DeprecatedAttachs.update(
{
_id: doc._id,
},
@@ -240,7 +266,7 @@ if (Meteor.isServer) {
}
});
- Attachments.files.before.remove((userId, doc) => {
+ DeprecatedAttachs.files.before.remove((userId, doc) => {
Activities.insert({
userId,
type: 'card',
@@ -253,11 +279,16 @@ if (Meteor.isServer) {
});
});
- Attachments.files.after.remove((userId, doc) => {
+ DeprecatedAttachs.files.after.remove((userId, doc) => {
Activities.remove({
attachmentId: doc._id,
});
});
}
+function storagePath(defaultPath) {
+ const storePath = process.env.ATTACHMENTS_STORE_PATH;
+ return storePath ? storePath : defaultPath;
+}
+
export default Attachments;