summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorGhassen Rjab <rjab.ghassen@gmail.com>2017-07-15 22:10:46 +0100
committerGhassen Rjab <rjab.ghassen@gmail.com>2017-07-15 22:10:46 +0100
commit81e0d4e38203ec683aeac96e8fe7cb040170575b (patch)
tree71789a575a5c60f95b9ba9b8a7eba96fdec757c4 /models
parent52619ef622a4257001516cb63acd66af02832ff4 (diff)
downloadwekan-81e0d4e38203ec683aeac96e8fe7cb040170575b.tar.gz
wekan-81e0d4e38203ec683aeac96e8fe7cb040170575b.tar.bz2
wekan-81e0d4e38203ec683aeac96e8fe7cb040170575b.zip
Export and import attachents as base64 encoded files
Diffstat (limited to 'models')
-rw-r--r--models/export.js24
-rw-r--r--models/wekanCreator.js49
2 files changed, 56 insertions, 17 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,
};
});
diff --git a/models/wekanCreator.js b/models/wekanCreator.js
index b91b875a..ae2097cc 100644
--- a/models/wekanCreator.js
+++ b/models/wekanCreator.js
@@ -303,21 +303,40 @@ export class WekanCreator {
// - the template then tries to display the url to the attachment which causes other errors
// so we make it server only, and let UI catch up once it is done, forget about latency comp.
if(Meteor.isServer) {
- file.attachData(att.url, function (error) {
- file.boardId = boardId;
- file.cardId = cardId;
- if (error) {
- throw(error);
- } else {
- const wekanAtt = Attachments.insert(file, () => {
- // we do nothing
- });
- //
- if(wekanCoverId === att._id) {
- Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
+ if (att.url) {
+ file.attachData(att.url, function (error) {
+ file.boardId = boardId;
+ file.cardId = cardId;
+ if (error) {
+ throw(error);
+ } else {
+ const wekanAtt = Attachments.insert(file, () => {
+ // we do nothing
+ });
+ //
+ if(wekanCoverId === att._id) {
+ Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
+ }
}
- }
- });
+ });
+ } else if (att.file) {
+ file.attachData(new Buffer(att.file, 'base64'), {type: att.type}, (error) => {
+ file.name(att.name);
+ file.boardId = boardId;
+ file.cardId = cardId;
+ if (error) {
+ throw(error);
+ } else {
+ const wekanAtt = Attachments.insert(file, () => {
+ // we do nothing
+ });
+ //
+ if(wekanCoverId === att._id) {
+ Cards.direct.update(cardId, { $set: {coverId: wekanAtt._id}});
+ }
+ }
+ });
+ }
}
// todo XXX set cover - if need be
});
@@ -406,7 +425,7 @@ export class WekanCreator {
const wekanAttachment = wekanBoard.attachments.filter((attachment) => {
return attachment._id === activity.attachmentId;
})[0];
- if(wekanAttachment.url) {
+ if(wekanAttachment.url || wekanAttachment.file) {
// we cannot actually create the Wekan attachment, because we don't yet
// have the cards to attach it to, so we store it in the instance variable.
const wekanCardId = activity.cardId;