فهرست منبع

Meteor-Files 2.2.1 changed the function "namingFunction"

See also:
https://github.com/veliovgroup/Meteor-Files/commit/f872569be282e3abfd1d812ab72cdd1b446273fa
Martin Filser 3 سال پیش
والد
کامیت
344aeb4051
1فایلهای تغییر یافته به همراه18 افزوده شده و 7 حذف شده
  1. 18 7
      models/attachments.js

+ 18 - 7
models/attachments.js

@@ -53,17 +53,28 @@ Attachments = new FilesCollection({
   debug: false, // Change to `true` for debugging
   collectionName: 'attachments',
   allowClientCode: true,
-/* Commenting out because this custom namingFunction did not work:
-   https://github.com/veliovgroup/Meteor-Files/issues/847
-
   namingFunction(opts) {
-    const filenameWithoutExtension = opts.meta.name.replace(/(.+)\..+/, "$1");
-    const ret = opts.meta.fileId + "-original-" + filenameWithoutExtension;
+    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
+      filenameWithoutExtension = opts.file.name.replace(new RegExp(opts.file.extensionWithDot + "$"), "")
+      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
-    delete opts.meta.fileId;
     return ret;
   },
-*/
   storagePath() {
     const ret = fileStoreStrategyFactory.storagePath;
     return ret;