diff options
author | Lauri Ojansivu <x@xet7.org> | 2017-07-19 21:20:40 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2017-07-19 21:20:40 +0300 |
commit | 57f9c1df69c61fc0d2921f89309df9262935356d (patch) | |
tree | 9c2a77164560a45edf196972b2a066f975329263 /models/export.js | |
parent | 52619ef622a4257001516cb63acd66af02832ff4 (diff) | |
parent | f3f15f83b0a85ee3bf0c74b7a66d0dff43d678db (diff) | |
download | wekan-57f9c1df69c61fc0d2921f89309df9262935356d.tar.gz wekan-57f9c1df69c61fc0d2921f89309df9262935356d.tar.bz2 wekan-57f9c1df69c61fc0d2921f89309df9262935356d.zip |
Merge branch 'GhassenRjab-attachment-base64' into devel
Export and import attachments as base64 encoded files. Thanks to GhassenRjab !
Update translations.
Diffstat (limited to 'models/export.js')
-rw-r--r-- | models/export.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/models/export.js b/models/export.js index 7b22f45d..7243cf24 100644 --- a/models/export.js +++ b/models/export.js @@ -55,12 +55,32 @@ class Exporter { result.cards = Cards.find(byBoard, noBoardId).fetch(); result.comments = CardComments.find(byBoard, noBoardId).fetch(); result.activities = Activities.find(byBoard, noBoardId).fetch(); - // for attachments we only export IDs and absolute url to original doc + // [Old] for attachments we only export IDs and absolute url to original doc + // [New] Encode attachment to base64 + const getBase64Data = function(doc, callback) { + let buffer = new Buffer(0); + // callback has the form function (err, res) {} + const readStream = doc.createReadStream(); + readStream.on('data', function(chunk) { + buffer = Buffer.concat([buffer, chunk]); + }); + readStream.on('error', function(err) { + callback(err, null); + }); + readStream.on('end', function() { + // done + callback(null, buffer.toString('base64')); + }); + }; + const getBase64DataSync = Meteor.wrapAsync(getBase64Data); result.attachments = Attachments.find(byBoard).fetch().map((attachment) => { return { _id: attachment._id, cardId: attachment.cardId, - url: FlowRouter.url(attachment.url()), + // url: FlowRouter.url(attachment.url()), + file: getBase64DataSync(attachment), + name: attachment.original.name, + type: attachment.original.type, }; }); |