mirror of
https://github.com/wekan/wekan.git
synced 2025-12-22 18:30:13 +01:00
Export and import attachents as base64 encoded files
This commit is contained in:
parent
52619ef622
commit
81e0d4e382
2 changed files with 56 additions and 17 deletions
|
|
@ -55,12 +55,32 @@ class Exporter {
|
||||||
result.cards = Cards.find(byBoard, noBoardId).fetch();
|
result.cards = Cards.find(byBoard, noBoardId).fetch();
|
||||||
result.comments = CardComments.find(byBoard, noBoardId).fetch();
|
result.comments = CardComments.find(byBoard, noBoardId).fetch();
|
||||||
result.activities = Activities.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) => {
|
result.attachments = Attachments.find(byBoard).fetch().map((attachment) => {
|
||||||
return {
|
return {
|
||||||
_id: attachment._id,
|
_id: attachment._id,
|
||||||
cardId: attachment.cardId,
|
cardId: attachment.cardId,
|
||||||
url: FlowRouter.url(attachment.url()),
|
// url: FlowRouter.url(attachment.url()),
|
||||||
|
file: getBase64DataSync(attachment),
|
||||||
|
name: attachment.original.name,
|
||||||
|
type: attachment.original.type,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,7 @@ export class WekanCreator {
|
||||||
// - the template then tries to display the url to the attachment which causes other errors
|
// - 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.
|
// so we make it server only, and let UI catch up once it is done, forget about latency comp.
|
||||||
if(Meteor.isServer) {
|
if(Meteor.isServer) {
|
||||||
|
if (att.url) {
|
||||||
file.attachData(att.url, function (error) {
|
file.attachData(att.url, function (error) {
|
||||||
file.boardId = boardId;
|
file.boardId = boardId;
|
||||||
file.cardId = cardId;
|
file.cardId = cardId;
|
||||||
|
|
@ -318,6 +319,24 @@ export class WekanCreator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} 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
|
// todo XXX set cover - if need be
|
||||||
});
|
});
|
||||||
|
|
@ -406,7 +425,7 @@ export class WekanCreator {
|
||||||
const wekanAttachment = wekanBoard.attachments.filter((attachment) => {
|
const wekanAttachment = wekanBoard.attachments.filter((attachment) => {
|
||||||
return attachment._id === activity.attachmentId;
|
return attachment._id === activity.attachmentId;
|
||||||
})[0];
|
})[0];
|
||||||
if(wekanAttachment.url) {
|
if(wekanAttachment.url || wekanAttachment.file) {
|
||||||
// we cannot actually create the Wekan attachment, because we don't yet
|
// 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.
|
// have the cards to attach it to, so we store it in the instance variable.
|
||||||
const wekanCardId = activity.cardId;
|
const wekanCardId = activity.cardId;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue