From 25443926d3a7cfbc0786de68ab141e062cdbc93a Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Thu, 18 Aug 2022 21:12:33 +0200 Subject: [PATCH 1/3] Attachment, path was wrong if the file hasn't a extension --- models/attachments.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/attachments.js b/models/attachments.js index 3816a407a..6bd73e4b7 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -59,7 +59,12 @@ Attachments = new FilesCollection({ delete opts.meta.fileId; } else if (opts?.file?.name) { // Server - filenameWithoutExtension = opts.file.name.replace(new RegExp(opts.file.extensionWithDot + "$"), "") + if (opts.file.extension) { + filenameWithoutExtension = opts.file.name.replace(new RegExp(opts.file.extensionWithDot + "$"), "") + } else { + // file has no extension, so don't replace anything, otherwise the last character is removed (because extensionWithDot = '.') + filenameWithoutExtension = opts.file.name; + } fileId = opts.fileId; } else { From f6fbd0a5c2110a6ded6452d81c054e2a1f9c309f Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Thu, 18 Aug 2022 17:30:46 +0200 Subject: [PATCH 2/3] Attachment, rename not needed anymore since Meteor-Files 2.3.0 Thanks to @dr-dimitru https://github.com/wekan/wekan/pull/4638#issuecomment-1217883870 https://github.com/veliovgroup/Meteor-Files/commit/00ab6f723b84eb596b366c5d26e6981a00377809 --- .meteor/packages | 2 +- models/attachments.js | 7 ++++--- models/avatars.js | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index e6039d463..5b1170eab 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -81,7 +81,7 @@ konecty:mongo-counter percolate:synced-cron cfs:filesystem ostrio:cookies -ostrio:files@2.0.1 +ostrio:files@2.3.0 rajit:bootstrap3-datepicker-fi rajit:bootstrap3-datepicker-ar rajit:bootstrap3-datepicker-bg diff --git a/models/attachments.js b/models/attachments.js index 6bd73e4b7..4478a25c8 100644 --- a/models/attachments.js +++ b/models/attachments.js @@ -76,6 +76,10 @@ Attachments = new FilesCollection({ // remove fileId from meta, it was only stored there to have this information here in the namingFunction function return ret; }, + sanitize(str, max, replacement) { + // keep the original filename + return str; + }, storagePath() { const ret = fileStoreStrategyFactory.storagePath; return ret; @@ -141,9 +145,6 @@ if (Meteor.isServer) { const fileObj = Attachments.findOne({_id: fileObjId}); moveToStorage(fileObj, storageDestination, fileStoreStrategyFactory); - - // since Meteor-Files 2.1.0 the filename is truncated to 28 characters, so rename the file after upload to the right filename back - rename(fileObj, fileObj.name, fileStoreStrategyFactory); }, renameAttachment(fileObjId, newName) { check(fileObjId, String); diff --git a/models/avatars.js b/models/avatars.js index bc95bc1b6..79fe19ca9 100644 --- a/models/avatars.js +++ b/models/avatars.js @@ -45,6 +45,10 @@ Avatars = new FilesCollection({ debug: false, // Change to `true` for debugging collectionName: 'avatars', allowClientCode: true, + sanitize(str, max, replacement) { + // keep the original filename + return str; + }, storagePath() { const ret = fileStoreStrategyFactory.storagePath; return ret; From f4e11ff7c5b7faf41c978d9ef4fc16600c28c90c Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Thu, 18 Aug 2022 21:31:23 +0200 Subject: [PATCH 3/3] Avatars, use same namingFunction as Attachments --- models/avatars.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/models/avatars.js b/models/avatars.js index 79fe19ca9..4fe19ddd4 100644 --- a/models/avatars.js +++ b/models/avatars.js @@ -45,6 +45,33 @@ Avatars = new FilesCollection({ debug: false, // Change to `true` for debugging collectionName: 'avatars', allowClientCode: true, + namingFunction(opts) { + let filenameWithoutExtension = "" + let fileId = ""; + if (opts?.name) { + // Client + filenameWithoutExtension = opts.name.replace(/(.+)\..+/, "$1"); + fileId = opts.meta.fileId; + delete opts.meta.fileId; + } else if (opts?.file?.name) { + // Server + if (opts.file.extension) { + filenameWithoutExtension = opts.file.name.replace(new RegExp(opts.file.extensionWithDot + "$"), "") + } else { + // file has no extension, so don't replace anything, otherwise the last character is removed (because extensionWithDot = '.') + filenameWithoutExtension = opts.file.name; + } + fileId = opts.fileId; + } + else { + // should never reach here + filenameWithoutExtension = Math.random().toString(36).slice(2); + fileId = Math.random().toString(36).slice(2); + } + const ret = fileId + "-original-" + filenameWithoutExtension; + // remove fileId from meta, it was only stored there to have this information here in the namingFunction function + return ret; + }, sanitize(str, max, replacement) { // keep the original filename return str;