Ref: original & and use fileObj.meta

fileObj.meta is part of the ostrio:files API and be passed to the
constructor. This is less hacky than trying tu update a persistet object
after the fact.
This commit is contained in:
David Arnold 2020-09-14 01:07:17 -05:00 committed by Denis Perov
parent 16506e7a6a
commit e702f17c7b
10 changed files with 124 additions and 159 deletions

View file

@ -446,33 +446,31 @@ export class WekanCreator {
const wekanCoverId = card.coverId;
if (attachments && Meteor.isServer) {
attachments.forEach(att => {
// Simulating file.attachData on the client generates multiple errors
// - HEAD returns null, which causes exception down the line
// - 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.
const self = this;
if (att.url || att.file) {
Attachment.load(
att.url ? att.url : Buffer.from(att.file, 'base64'),
{ type: att.type ? att.ype : undefined },
(error, fileObj) => {
if (error) {
throw error;
}
fileObj.boardId = boardId;
fileObj.cardId = cardId;
fileObj.userId = self._user(att.userId);
// The field source will only be used to prevent adding
// attachments' related activities automatically
fileObj.source = 'import';
self.attachmentIds[att._id] = fileObj._id;
if (wekanCoverId === att._id) {
Cards.direct.update(cardId, {
$set: { coverId: fileObj._id },
});
}
},
);
const opts = {
type: att.type ? att.type : undefined,
userId: self._user(att.userId),
meta: {
boardId,
cardId,
source: 'import',
},
};
const cb = (error, fileObj) => {
if (error) {
throw error;
}
self.attachmentIds[att._id] = fileObj._id;
if (wekanCoverId === att._id) {
Cards.direct.update(cardId, {
$set: { coverId: fileObj._id },
});
}
};
if (att.url) {
Attachment.load(att.url, opts, cb, true);
} else if (att.file) {
Attachment.write(att.file, opts, cb, true);
}
});
}