mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 05:27:14 -04:00
Try to fix attachment migrations to ostrioFiles, allow existing files to be migrated. Part 2.
Thanks to xet7 ! Related #4780, related https://github.com/wekan/wekan/pull/4648
This commit is contained in:
parent
1aa5c23bba
commit
16ad6bf9fc
2 changed files with 31 additions and 27 deletions
|
@ -13,38 +13,38 @@ if (Meteor.isServer) {
|
|||
export async function isFileValid(fileObj, mimeTypesAllowed, sizeAllowed, externalCommandLine) {
|
||||
let isValid = true;
|
||||
|
||||
/*
|
||||
if (mimeTypesAllowed.length) {
|
||||
const mimeTypeResult = await FileType.fromFile(fileObj.path);
|
||||
if (Meteor.settings.public.ostrioFilesMigrationInProgress !== "true") {
|
||||
if (mimeTypesAllowed.length) {
|
||||
const mimeTypeResult = await FileType.fromFile(fileObj.path);
|
||||
|
||||
const mimeType = (mimeTypeResult ? mimeTypeResult.mime : fileObj.type);
|
||||
const baseMimeType = mimeType.split('/', 1)[0];
|
||||
const mimeType = (mimeTypeResult ? mimeTypeResult.mime : fileObj.type);
|
||||
const baseMimeType = mimeType.split('/', 1)[0];
|
||||
|
||||
isValid = mimeTypesAllowed.includes(mimeType) || mimeTypesAllowed.includes(baseMimeType + '/*') || mimeTypesAllowed.includes('*');
|
||||
isValid = mimeTypesAllowed.includes(mimeType) || mimeTypesAllowed.includes(baseMimeType + '/*') || mimeTypesAllowed.includes('*');
|
||||
|
||||
if (!isValid) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " - mimetype " + mimeType);
|
||||
if (!isValid) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " - mimetype " + mimeType);
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid && sizeAllowed && fileObj.size > sizeAllowed) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " - size " + fileObj.size);
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
if (isValid && externalCommandLine) {
|
||||
await asyncExec(externalCommandLine.replace("{file}", '"' + fileObj.path + '"'));
|
||||
isValid = fs.existsSync(fileObj.path);
|
||||
|
||||
if (!isValid) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " has been deleted externally");
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
console.debug("Validation of uploaded file successful: file " + fileObj.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid && sizeAllowed && fileObj.size > sizeAllowed) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " - size " + fileObj.size);
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
if (isValid && externalCommandLine) {
|
||||
await asyncExec(externalCommandLine.replace("{file}", '"' + fileObj.path + '"'));
|
||||
isValid = fs.existsSync(fileObj.path);
|
||||
|
||||
if (!isValid) {
|
||||
console.log("Validation of uploaded file failed: file " + fileObj.path + " has been deleted externally");
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
console.debug("Validation of uploaded file successful: file " + fileObj.path);
|
||||
}
|
||||
*/
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
|
|
@ -1246,6 +1246,7 @@ Migrations.add('add-card-details-show-lists', () => {
|
|||
});
|
||||
|
||||
Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
||||
Meteor.settings.public.ostrioFilesMigrationInProgress = "true";
|
||||
AttachmentsOld.find().forEach(function(fileObj) {
|
||||
const newFileName = fileObj.name();
|
||||
const storagePath = Attachments.storagePath({});
|
||||
|
@ -1306,9 +1307,11 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
|||
|
||||
readStream.pipe(writeStream);
|
||||
});
|
||||
Meteor.settings.public.ostrioFilesMigrationInProgress = "false";
|
||||
});
|
||||
|
||||
Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
||||
Meteor.settings.public.ostrioFilesMigrationInProgress = "true";
|
||||
AvatarsOld.find().forEach(function(fileObj) {
|
||||
const newFileName = fileObj.name();
|
||||
const storagePath = Avatars.storagePath({});
|
||||
|
@ -1386,6 +1389,7 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
|||
|
||||
readStream.pipe(writeStream);
|
||||
});
|
||||
Meteor.settings.public.ostrioFilesMigrationInProgress = "false";
|
||||
});
|
||||
|
||||
Migrations.add('migrate-attachment-drop-index-cardId', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue