From e01f4dbf1393a789faaa2f38b53d2effad827e86 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 11 Jan 2020 13:08:29 +0200 Subject: Change Buffer to Buffer.alloc on Node v12. Try to fix Snap. --- models/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/export.js') diff --git a/models/export.js b/models/export.js index cc979ce0..69aaf619 100644 --- a/models/export.js +++ b/models/export.js @@ -138,7 +138,7 @@ export class Exporter { // [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); + let buffer = new Buffer.alloc(0); // callback has the form function (err, res) {} const tmpFile = path.join( os.tmpdir(), -- cgit v1.2.3-1-g7c22 From 9b905c2833d54cf34d1875148075b2bf756d943a Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 18 Jan 2020 16:01:02 +0200 Subject: Try to fix Node 12 Buffer() deprecation errors. Thanks to xet7 ! --- models/export.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/export.js') diff --git a/models/export.js b/models/export.js index 69aaf619..cd72a6a4 100644 --- a/models/export.js +++ b/models/export.js @@ -138,7 +138,7 @@ export class Exporter { // [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.alloc(0); + let buffer = Buffer.from(0); // callback has the form function (err, res) {} const tmpFile = path.join( os.tmpdir(), -- cgit v1.2.3-1-g7c22 From f868b3d1f977824ca1dc9fc45f0251ed4019b21e Mon Sep 17 00:00:00 2001 From: izadpoor Date: Thu, 23 Jan 2020 01:16:56 -0500 Subject: fixed board export with attchment --- models/export.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'models/export.js') diff --git a/models/export.js b/models/export.js index cd72a6a4..339123c8 100644 --- a/models/export.js +++ b/models/export.js @@ -24,7 +24,6 @@ if (Meteor.isServer) { JsonRoutes.add('get', '/api/boards/:boardId/export', function(req, res) { const boardId = req.params.boardId; let user = null; - const loginToken = req.query.authToken; if (loginToken) { const hashToken = Accounts._hashLoginToken(loginToken); @@ -35,7 +34,6 @@ if (Meteor.isServer) { Authentication.checkUserId(req.userId); user = Users.findOne({ _id: req.userId, isAdmin: true }); } - const exporter = new Exporter(boardId); if (exporter.canExport(user)) { JsonRoutes.sendResult(res, { @@ -137,8 +135,11 @@ export class Exporter { // [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 = Buffer.from(0); + let buffer = Buffer.allocUnsafe(0); + buffer.fill(0); + // callback has the form function (err, res) {} const tmpFile = path.join( os.tmpdir(), @@ -149,14 +150,16 @@ export class Exporter { readStream.on('data', function(chunk) { buffer = Buffer.concat([buffer, chunk]); }); + readStream.on('error', function(err) { - callback(err, null); + callback(null, null); }); readStream.on('end', function() { // done fs.unlink(tmpFile, () => { //ignored }); + callback(null, buffer.toString('base64')); }); readStream.pipe(tmpWriteable); @@ -165,11 +168,14 @@ export class Exporter { result.attachments = Attachments.find(byBoard) .fetch() .map(attachment => { + let filebase64 = null; + filebase64 = getBase64DataSync(attachment); + return { _id: attachment._id, cardId: attachment.cardId, - // url: FlowRouter.url(attachment.url()), - file: getBase64DataSync(attachment), + //url: FlowRouter.url(attachment.url()), + file: filebase64, name: attachment.original.name, type: attachment.original.type, }; -- cgit v1.2.3-1-g7c22