mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Merge pull request #4496 from mfilser/upgrade-meteor-2.7.2-fix_copy_board
Upgrade meteor 2.7.2 - fix copy board
This commit is contained in:
commit
0865f3597a
4 changed files with 65 additions and 11 deletions
|
@ -260,7 +260,7 @@ BlazeComponent.extendComponent({
|
|||
},
|
||||
(err, res) => {
|
||||
if (err) {
|
||||
self.setError(err.error);
|
||||
console.error(err);
|
||||
} else {
|
||||
Session.set('fromBoard', null);
|
||||
subManager.subscribe('board', res, false);
|
||||
|
@ -268,7 +268,6 @@ BlazeComponent.extendComponent({
|
|||
id: res,
|
||||
slug: title,
|
||||
});
|
||||
//Utils.goBoardId(res);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -34,12 +34,13 @@ Attachments = new FilesCollection({
|
|||
return ret;
|
||||
},
|
||||
onAfterUpload(fileObj) {
|
||||
let storage = fileObj.meta.copyStorage || STORAGE_NAME_GRIDFS;
|
||||
// current storage is the filesystem, update object and database
|
||||
Object.keys(fileObj.versions).forEach(versionName => {
|
||||
fileObj.versions[versionName].storage = STORAGE_NAME_FILESYSTEM;
|
||||
});
|
||||
Attachments.update({ _id: fileObj._id }, { $set: { "versions" : fileObj.versions } });
|
||||
moveToStorage(fileObj, STORAGE_NAME_GRIDFS, fileStoreStrategyFactory);
|
||||
moveToStorage(fileObj, storage, fileStoreStrategyFactory);
|
||||
},
|
||||
interceptDownload(http, fileObj, versionName) {
|
||||
const ret = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName).interceptDownload(http, this.cacheControl);
|
||||
|
|
|
@ -5,7 +5,8 @@ import {
|
|||
TYPE_LINKED_BOARD,
|
||||
TYPE_LINKED_CARD,
|
||||
} from '../config/const';
|
||||
import Attachments from "./attachments";
|
||||
import Attachments, { fileStoreStrategyFactory } from "./attachments";
|
||||
import { copyFile } from './lib/fileStoreStrategy.js';
|
||||
|
||||
|
||||
Cards = new Mongo.Collection('cards');
|
||||
|
@ -586,11 +587,11 @@ Cards.helpers({
|
|||
const _id = Cards.insert(this);
|
||||
|
||||
// Copy attachments
|
||||
oldCard.attachments().forEach(att => {
|
||||
att.cardId = _id;
|
||||
delete att._id;
|
||||
return Attachments.insert(att);
|
||||
});
|
||||
oldCard.attachments()
|
||||
.map(att => att.get())
|
||||
.forEach(att => {
|
||||
copyFile(att, _id, fileStoreStrategyFactory);
|
||||
});
|
||||
|
||||
// copy checklists
|
||||
Checklists.find({ cardId: oldId }).forEach(ch => {
|
||||
|
|
|
@ -312,11 +312,11 @@ export const moveToStorage = function(fileObj, storageDestination, fileStoreStra
|
|||
const writeStream = strategyWrite.getWriteStream(filePath);
|
||||
|
||||
writeStream.on('error', error => {
|
||||
console.error('[writeStream error]: ', error, fileObjId);
|
||||
console.error('[writeStream error]: ', error, fileObj._id);
|
||||
});
|
||||
|
||||
readStream.on('error', error => {
|
||||
console.error('[readStream error]: ', error, fileObjId);
|
||||
console.error('[readStream error]: ', error, fileObj._id);
|
||||
});
|
||||
|
||||
writeStream.on('finish', Meteor.bindEnvironment((finishedData) => {
|
||||
|
@ -336,3 +336,56 @@ 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,
|
||||
copyStorage: strategyRead.getStorageName(),
|
||||
},
|
||||
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