mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 07:50:12 +01:00
Board copy work now again
- there was an error at attachment copy - fixes: https://github.com/wekan/wekan/issues/4485#issue-1211353265
This commit is contained in:
parent
58d760a615
commit
fbb0ed5ec1
3 changed files with 60 additions and 8 deletions
|
|
@ -260,7 +260,7 @@ BlazeComponent.extendComponent({
|
||||||
},
|
},
|
||||||
(err, res) => {
|
(err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.setError(err.error);
|
console.error(err);
|
||||||
} else {
|
} else {
|
||||||
Session.set('fromBoard', null);
|
Session.set('fromBoard', null);
|
||||||
subManager.subscribe('board', res, false);
|
subManager.subscribe('board', res, false);
|
||||||
|
|
@ -268,7 +268,6 @@ BlazeComponent.extendComponent({
|
||||||
id: res,
|
id: res,
|
||||||
slug: title,
|
slug: title,
|
||||||
});
|
});
|
||||||
//Utils.goBoardId(res);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ import {
|
||||||
TYPE_LINKED_BOARD,
|
TYPE_LINKED_BOARD,
|
||||||
TYPE_LINKED_CARD,
|
TYPE_LINKED_CARD,
|
||||||
} from '../config/const';
|
} from '../config/const';
|
||||||
import Attachments from "./attachments";
|
import Attachments, { fileStoreStrategyFactory } from "./attachments";
|
||||||
|
import { copyFile } from './lib/fileStoreStrategy.js';
|
||||||
|
|
||||||
|
|
||||||
Cards = new Mongo.Collection('cards');
|
Cards = new Mongo.Collection('cards');
|
||||||
|
|
@ -586,11 +587,11 @@ Cards.helpers({
|
||||||
const _id = Cards.insert(this);
|
const _id = Cards.insert(this);
|
||||||
|
|
||||||
// Copy attachments
|
// Copy attachments
|
||||||
oldCard.attachments().forEach(att => {
|
oldCard.attachments()
|
||||||
att.cardId = _id;
|
.map(att => att.get())
|
||||||
delete att._id;
|
.forEach(att => {
|
||||||
return Attachments.insert(att);
|
copyFile(att, _id, fileStoreStrategyFactory);
|
||||||
});
|
});
|
||||||
|
|
||||||
// copy checklists
|
// copy checklists
|
||||||
Checklists.find({ cardId: oldId }).forEach(ch => {
|
Checklists.find({ cardId: oldId }).forEach(ch => {
|
||||||
|
|
|
||||||
|
|
@ -336,3 +336,55 @@ export const moveToStorage = function(fileObj, storageDestination, fileStoreStra
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const copyFile = function(fileObj, newCardId, fileStoreStrategyFactory) {
|
||||||
|
const versionName = "original";
|
||||||
|
const strategyRead = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName);
|
||||||
|
const readStream = strategyRead.getReadStream();
|
||||||
|
const strategyWrite = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName, STORAGE_NAME_FILESYSTEM);
|
||||||
|
|
||||||
|
const tempPath = path.join(fileStoreStrategyFactory.storagePath, Random.id() + "-" + versionName + "-" + fileObj.name);
|
||||||
|
const writeStream = strategyWrite.getWriteStream(tempPath);
|
||||||
|
|
||||||
|
writeStream.on('error', error => {
|
||||||
|
console.error('[writeStream error]: ', error, fileObj._id);
|
||||||
|
});
|
||||||
|
|
||||||
|
readStream.on('error', error => {
|
||||||
|
console.error('[readStream error]: ', error, fileObj._id);
|
||||||
|
});
|
||||||
|
|
||||||
|
// https://forums.meteor.com/t/meteor-code-must-always-run-within-a-fiber-try-wrapping-callbacks-that-you-pass-to-non-meteor-libraries-with-meteor-bindenvironmen/40099/8
|
||||||
|
readStream.on('end', Meteor.bindEnvironment(() => {
|
||||||
|
const fileId = Random.id();
|
||||||
|
Attachments.addFile(
|
||||||
|
tempPath,
|
||||||
|
{
|
||||||
|
fileName: fileObj.name,
|
||||||
|
type: fileObj.type,
|
||||||
|
meta: {
|
||||||
|
boardId: fileObj.meta.boardId,
|
||||||
|
cardId: newCardId,
|
||||||
|
listId: fileObj.meta.listId,
|
||||||
|
swimlaneId: fileObj.meta.swimlaneId,
|
||||||
|
source: 'copy',
|
||||||
|
copyFrom: fileObj._id,
|
||||||
|
},
|
||||||
|
userId: fileObj.userId,
|
||||||
|
size: fileObj.fileSize,
|
||||||
|
fileId,
|
||||||
|
},
|
||||||
|
(err, fileRef) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
// Set the userId again
|
||||||
|
Attachments.update({ _id: fileRef._id }, { $set: { userId: fileObj.userId } });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
readStream.pipe(writeStream);
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue