summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorizadpoor <h_izadpoor@yahoo.com>2020-01-23 01:16:56 -0500
committerizadpoor <h_izadpoor@yahoo.com>2020-01-23 01:16:56 -0500
commitf868b3d1f977824ca1dc9fc45f0251ed4019b21e (patch)
tree30fa61a1456c91702c85293273c009697cccdb49 /models
parent70f5326099dc9cfbf1b62d2dcb6ed09aa28174b3 (diff)
downloadwekan-f868b3d1f977824ca1dc9fc45f0251ed4019b21e.tar.gz
wekan-f868b3d1f977824ca1dc9fc45f0251ed4019b21e.tar.bz2
wekan-f868b3d1f977824ca1dc9fc45f0251ed4019b21e.zip
fixed board export with attchment
Diffstat (limited to 'models')
-rw-r--r--models/export.js18
1 files changed, 12 insertions, 6 deletions
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,
};