mirror of
https://github.com/wekan/wekan.git
synced 2025-12-22 18:30:13 +01:00
Copy attachment copies now all versions
- for now only the version "original" exists, but as other method already consider that other version's can exist
This commit is contained in:
parent
e37bf2b51d
commit
1516615934
1 changed files with 45 additions and 44 deletions
|
|
@ -353,56 +353,57 @@ export const moveToStorage = function(fileObj, storageDestination, fileStoreStra
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyFile = function(fileObj, newCardId, fileStoreStrategyFactory) {
|
export const copyFile = function(fileObj, newCardId, fileStoreStrategyFactory) {
|
||||||
const versionName = "original";
|
Object.keys(fileObj.versions).forEach(versionName => {
|
||||||
const strategyRead = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName);
|
const strategyRead = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName);
|
||||||
const readStream = strategyRead.getReadStream();
|
const readStream = strategyRead.getReadStream();
|
||||||
const strategyWrite = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName, STORAGE_NAME_FILESYSTEM);
|
const strategyWrite = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName, STORAGE_NAME_FILESYSTEM);
|
||||||
|
|
||||||
const tempPath = path.join(fileStoreStrategyFactory.storagePath, Random.id() + "-" + versionName + "-" + fileObj.name);
|
const tempPath = path.join(fileStoreStrategyFactory.storagePath, Random.id() + "-" + versionName + "-" + fileObj.name);
|
||||||
const writeStream = strategyWrite.getWriteStream(tempPath);
|
const writeStream = strategyWrite.getWriteStream(tempPath);
|
||||||
|
|
||||||
writeStream.on('error', error => {
|
writeStream.on('error', error => {
|
||||||
console.error('[writeStream error]: ', error, fileObj._id);
|
console.error('[writeStream error]: ', error, fileObj._id);
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.on('error', error => {
|
readStream.on('error', error => {
|
||||||
console.error('[readStream error]: ', error, fileObj._id);
|
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
|
// 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(() => {
|
readStream.on('end', Meteor.bindEnvironment(() => {
|
||||||
const fileId = Random.id();
|
const fileId = Random.id();
|
||||||
Attachments.addFile(
|
Attachments.addFile(
|
||||||
tempPath,
|
tempPath,
|
||||||
{
|
{
|
||||||
fileName: fileObj.name,
|
fileName: fileObj.name,
|
||||||
type: fileObj.type,
|
type: fileObj.type,
|
||||||
meta: {
|
meta: {
|
||||||
boardId: fileObj.meta.boardId,
|
boardId: fileObj.meta.boardId,
|
||||||
cardId: newCardId,
|
cardId: newCardId,
|
||||||
listId: fileObj.meta.listId,
|
listId: fileObj.meta.listId,
|
||||||
swimlaneId: fileObj.meta.swimlaneId,
|
swimlaneId: fileObj.meta.swimlaneId,
|
||||||
source: 'copy',
|
source: 'copy',
|
||||||
copyFrom: fileObj._id,
|
copyFrom: fileObj._id,
|
||||||
copyStorage: strategyRead.getStorageName(),
|
copyStorage: strategyRead.getStorageName(),
|
||||||
|
},
|
||||||
|
userId: fileObj.userId,
|
||||||
|
size: fileObj.fileSize,
|
||||||
|
fileId,
|
||||||
},
|
},
|
||||||
userId: fileObj.userId,
|
(err, fileRef) => {
|
||||||
size: fileObj.fileSize,
|
if (err) {
|
||||||
fileId,
|
console.log(err);
|
||||||
},
|
} else {
|
||||||
(err, fileRef) => {
|
// Set the userId again
|
||||||
if (err) {
|
Attachments.update({ _id: fileRef._id }, { $set: { userId: fileObj.userId } });
|
||||||
console.log(err);
|
}
|
||||||
} else {
|
},
|
||||||
// Set the userId again
|
true,
|
||||||
Attachments.update({ _id: fileRef._id }, { $set: { userId: fileObj.userId } });
|
);
|
||||||
}
|
}));
|
||||||
},
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
readStream.pipe(writeStream);
|
readStream.pipe(writeStream);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const rename = function(fileObj, newName, fileStoreStrategyFactory) {
|
export const rename = function(fileObj, newName, fileStoreStrategyFactory) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue