diff options
-rw-r--r-- | models/export.js | 33 | ||||
-rw-r--r-- | server/lib/utils.js | 21 |
2 files changed, 38 insertions, 16 deletions
diff --git a/models/export.js b/models/export.js index c20053ad..9fbcbcef 100644 --- a/models/export.js +++ b/models/export.js @@ -19,19 +19,6 @@ if(Meteor.isServer) { }); } - -Meteor.methods({ - exportBoard(boardId) { - check(boardId, String); - const exporter = new Exporter(boardId); - if(exporter.canExport(Meteor.user())) { - return exporter.build(); - } else { - throw new Meteor.Error('error-board-notAMember'); - } - }, -}); - class Exporter { constructor(boardId) { this._boardId = boardId; @@ -41,12 +28,20 @@ class Exporter { const byBoard = {boardId: this._boardId}; // we do not want to retrieve boardId in related elements const noBoardId = {fields: {boardId: 0}}; - const result = Boards.findOne(this._boardId, {fields: {stars: 0}}); - result._format = 'wekan-board-1.0.0'; + const result = { + _format: 'wekan-board-1.0.0', + }; + _.extend(result, Boards.findOne(this._boardId, {fields: {stars: 0}})); result.lists = Lists.find(byBoard, noBoardId).fetch(); 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 + result.attachments = Attachments.find(byBoard).fetch().map((attachment) => { return { + _id: attachment._id, + cardId: attachment.cardId, + url: Meteor.absoluteUrl(Utils.stripLeadingSlash(attachment.url())), + };}); // we also have to export some user data - as the other elements only include id // but we have to be careful: @@ -73,7 +68,13 @@ class Exporter { 'profile.initials': 1, 'profile.avatarUrl': 1, }}; - result.users = Users.find(byUserIds, userFields).fetch(); + result.users = Users.find(byUserIds, userFields).fetch().map((user) => { + // user avatar is stored as a relative url, we export absolute + if(user.profile.avatarUrl) { + user.profile.avatarUrl = Meteor.absoluteUrl(Utils.stripLeadingSlash(user.profile.avatarUrl)); + } + return user; + }); return result; } diff --git a/server/lib/utils.js b/server/lib/utils.js index b59671fb..a6a84f90 100644 --- a/server/lib/utils.js +++ b/server/lib/utils.js @@ -5,3 +5,24 @@ allowIsBoardAdmin = function(userId, board) { allowIsBoardMember = function(userId, board) { return board && board.hasMember(userId); }; + +// todo XXX not really server-specific, +// so move it to a common (client+server) lib? +Utils = { + /** + * If text starts with a / will remove it. + * @param text + */ + stripLeadingSlash(text) { + // we need an actual text string + if (!text) { + return text; + } + // if starting with slash + if (text[0] === '/') { + return text.slice(1); + } + // otherwise leave untouched + return text; + }, +}; |