diff options
author | Romulus Urakagi Tsai <urakagi@gmail.com> | 2020-05-14 14:55:54 +0800 |
---|---|---|
committer | Romulus Urakagi Tsai <urakagi@gmail.com> | 2020-05-14 14:55:54 +0800 |
commit | 4c5a2fbd1f8ad2f2447235442bf96b893f18a409 (patch) | |
tree | b25338d6f8aed0bf523d31ab0e676ce474271998 /models | |
parent | 012ca39a8dc29517aef191e85325f3e5889daf37 (diff) | |
download | wekan-4c5a2fbd1f8ad2f2447235442bf96b893f18a409.tar.gz wekan-4c5a2fbd1f8ad2f2447235442bf96b893f18a409.tar.bz2 wekan-4c5a2fbd1f8ad2f2447235442bf96b893f18a409.zip |
Card clone OK
Diffstat (limited to 'models')
-rw-r--r-- | models/attachments.js | 35 | ||||
-rw-r--r-- | models/cards.js | 12 |
2 files changed, 41 insertions, 6 deletions
diff --git a/models/attachments.js b/models/attachments.js index d469f702..1a55cb85 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -1,4 +1,5 @@ import { FilesCollection } from 'meteor/ostrio:files'; +const fs = require('fs'); const collectionName = 'attachments2'; @@ -19,6 +20,36 @@ if (Meteor.isServer) { // TODO: Permission related // TODO: Add Activity update + Meteor.methods({ + cloneAttachment(file, overrides) { + check(file, Object); + check(overrides, Match.Maybe(Object)); + const path = file.path; + const opts = { + fileName: file.name, + type: file.type, + meta: file.meta, + userId: file.userId + }; + for (let key in overrides) { + if (key === 'meta') { + for (let metaKey in overrides.meta) { + opts.meta[metaKey] = overrides.meta[metaKey]; + } + } else { + opts[key] = overrides[key]; + } + } + const buffer = fs.readFileSync(path); + Attachments.write(buffer, opts, (err, fileRef) => { + if (err) { + console.log('Error when cloning record', err); + } + }); + return true; + } + }); + Meteor.publish(collectionName, function() { return Attachments.find().cursor; }); @@ -51,13 +82,13 @@ function onAttachmentUploaded(fileRef) { } else { // Don't add activity about adding the attachment as the activity // be imported and delete source field - CFSAttachments.update( + Attachments.collection.update( { _id: fileRef._id, }, { $unset: { - source: '', + 'meta.source': '', }, }, ); diff --git a/models/cards.js b/models/cards.js index 1236de1a..ae52ff04 100644 --- a/models/cards.js +++ b/models/cards.js @@ -402,10 +402,14 @@ Cards.helpers({ const _id = Cards.insert(this); // Copy attachments - oldCard.attachments().forEach(att => { - att.meta.cardId = _id; - delete att._id; - return Attachments.insert(att); + oldCard.attachments().forEach((file) => { + Meteor.call('cloneAttachment', file, + { + meta: { + cardId: _id + } + } + ); }); // copy checklists |