Bläddra i källkod

Fix missing profile/avatar pictures.

Thanks to kovacs-andras and xet7 !

Fixes #5147
Lauri Ojansivu 1 år sedan
förälder
incheckning
4e97a5351a
1 ändrade filer med 12 tillägg och 0 borttagningar
  1. 12 0
      models/users.js

+ 12 - 0
models/users.js

@@ -1888,6 +1888,18 @@ if (Meteor.isServer) {
     Users._collection.createIndex({
     Users._collection.createIndex({
       modifiedAt: -1,
       modifiedAt: -1,
     });
     });
+    // Avatar URLs from CollectionFS to Meteor-Files, at users collection avatarUrl field:
+    Users.find({ "profile.avatarUrl": { $regex: "/cfs/files/avatars/" } }).forEach(function (doc) {
+        doc.profile.avatarUrl = doc.profile.avatarUrl.replace("/cfs/files/avatars/", "/cdn/storage/avatars/");
+      Users.save(doc);
+    });
+    /* TODO: Optionally, for additional complexity:
+       a) Support SubURLs with parthname from ROOT_URL
+       b) Remove beginning or avatar URL, replace it with pathname and new avatar URL
+       c) Does all avatar and attachment URLs need to be fixed every time when starting or restarting?
+       d) What if avatar URL is at some other server? In that case, links would point incorrectly to this instance, if ROOT_URL and path part is removed.
+       doc.profile.avatarUrl = process.env.ROOT_URL.pathname + doc.profile.avatarUrl.replace("/cfs/files/avatars/", "/cdn/storage/avatars/").substring(str.indexOf("/cdn/storage/avatars"));
+    */
     /* Commented out extra index because of IndexOptionsConflict.
     /* Commented out extra index because of IndexOptionsConflict.
     Users._collection.createIndex(
     Users._collection.createIndex(
       {
       {