mirror of
https://github.com/wekan/wekan.git
synced 2025-12-19 17:00:13 +01:00
fixed board export with attchment
This commit is contained in:
parent
70f5326099
commit
f868b3d1f9
1 changed files with 12 additions and 6 deletions
|
|
@ -24,7 +24,6 @@ if (Meteor.isServer) {
|
||||||
JsonRoutes.add('get', '/api/boards/:boardId/export', function(req, res) {
|
JsonRoutes.add('get', '/api/boards/:boardId/export', function(req, res) {
|
||||||
const boardId = req.params.boardId;
|
const boardId = req.params.boardId;
|
||||||
let user = null;
|
let user = null;
|
||||||
|
|
||||||
const loginToken = req.query.authToken;
|
const loginToken = req.query.authToken;
|
||||||
if (loginToken) {
|
if (loginToken) {
|
||||||
const hashToken = Accounts._hashLoginToken(loginToken);
|
const hashToken = Accounts._hashLoginToken(loginToken);
|
||||||
|
|
@ -35,7 +34,6 @@ if (Meteor.isServer) {
|
||||||
Authentication.checkUserId(req.userId);
|
Authentication.checkUserId(req.userId);
|
||||||
user = Users.findOne({ _id: req.userId, isAdmin: true });
|
user = Users.findOne({ _id: req.userId, isAdmin: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const exporter = new Exporter(boardId);
|
const exporter = new Exporter(boardId);
|
||||||
if (exporter.canExport(user)) {
|
if (exporter.canExport(user)) {
|
||||||
JsonRoutes.sendResult(res, {
|
JsonRoutes.sendResult(res, {
|
||||||
|
|
@ -137,8 +135,11 @@ export class Exporter {
|
||||||
|
|
||||||
// [Old] 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
|
// [New] Encode attachment to base64
|
||||||
|
|
||||||
const getBase64Data = function(doc, callback) {
|
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) {}
|
// callback has the form function (err, res) {}
|
||||||
const tmpFile = path.join(
|
const tmpFile = path.join(
|
||||||
os.tmpdir(),
|
os.tmpdir(),
|
||||||
|
|
@ -149,14 +150,16 @@ export class Exporter {
|
||||||
readStream.on('data', function(chunk) {
|
readStream.on('data', function(chunk) {
|
||||||
buffer = Buffer.concat([buffer, chunk]);
|
buffer = Buffer.concat([buffer, chunk]);
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.on('error', function(err) {
|
readStream.on('error', function(err) {
|
||||||
callback(err, null);
|
callback(null, null);
|
||||||
});
|
});
|
||||||
readStream.on('end', function() {
|
readStream.on('end', function() {
|
||||||
// done
|
// done
|
||||||
fs.unlink(tmpFile, () => {
|
fs.unlink(tmpFile, () => {
|
||||||
//ignored
|
//ignored
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, buffer.toString('base64'));
|
callback(null, buffer.toString('base64'));
|
||||||
});
|
});
|
||||||
readStream.pipe(tmpWriteable);
|
readStream.pipe(tmpWriteable);
|
||||||
|
|
@ -165,11 +168,14 @@ export class Exporter {
|
||||||
result.attachments = Attachments.find(byBoard)
|
result.attachments = Attachments.find(byBoard)
|
||||||
.fetch()
|
.fetch()
|
||||||
.map(attachment => {
|
.map(attachment => {
|
||||||
|
let filebase64 = null;
|
||||||
|
filebase64 = getBase64DataSync(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),
|
file: filebase64,
|
||||||
name: attachment.original.name,
|
name: attachment.original.name,
|
||||||
type: attachment.original.type,
|
type: attachment.original.type,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue