Fix missing profile/avatar pictures.

Thanks to kovacs-andras and xet7 !

Fixes #5147
This commit is contained in:
Lauri Ojansivu 2023-11-09 12:11:36 +02:00
parent 2ab5009de7
commit 4e97a5351a

View file

@ -1888,6 +1888,18 @@ if (Meteor.isServer) {
Users._collection.createIndex({
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.
Users._collection.createIndex(
{