Save files serverside with filename ObjectID, without filename.

Thanks to g-roliveira, iamabrantes, Floaz, koelle25, scott-dunt, mfilser and xet7 !

Fixes #4416
pull/4903/head
Lauri Ojansivu 2 years ago
parent f0a6fa68ea
commit 76ac070f9b
  1. 7
      models/attachments.js
  2. 12
      server/migrations.js

@ -72,7 +72,12 @@ Attachments = new FilesCollection({
filenameWithoutExtension = Math.random().toString(36).slice(2);
fileId = Math.random().toString(36).slice(2);
}
const ret = fileId + "-original-" + filenameWithoutExtension;
// OLD:
//const ret = fileId + "-original-" + filenameWithoutExtension;
// NEW: Save file only with filename of ObjectID, not including filename.
// Fixes https://github.com/wekan/wekan/issues/4416#issuecomment-1510517168
const ret = fileId;
// remove fileId from meta, it was only stored there to have this information here in the namingFunction function
return ret;
},

@ -1250,7 +1250,11 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
AttachmentsOld.find().forEach(function(fileObj) {
const newFileName = fileObj.name();
const storagePath = Attachments.storagePath({});
const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
// OLD:
// const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
// NEW: Save file only with filename of ObjectID, not including filename.
// Fixes https://github.com/wekan/wekan/issues/4416#issuecomment-1510517168
const filePath = path.join(storagePath, `${fileObj._id}`);
// This is "example" variable, change it to the userId that you might be using.
const userId = fileObj.userId;
@ -1318,7 +1322,11 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
AvatarsOld.find().forEach(function(fileObj) {
const newFileName = fileObj.name();
const storagePath = Avatars.storagePath({});
const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
// OLD:
// const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
// NEW: Save file only with filename of ObjectID, not including filename.
// Fixes https://github.com/wekan/wekan/issues/4416#issuecomment-1510517168
const filePath = path.join(storagePath, `${fileObj._id}`);
// This is "example" variable, change it to the userId that you might be using.
const userId = fileObj.userId;

Loading…
Cancel
Save