瀏覽代碼

- Remove suburl from beginning of avatar file path, so that avatar images
don't get broken when root-url changes to different sub-url.
This does not change avatar urls in database, instead this
fixes url on the fly after loading avatar url from database.

Thanks to xet7 !

Closes #1776,
closes #386

Lauri Ojansivu 6 年之前
父節點
當前提交
7e0bc1e33a
共有 2 個文件被更改,包括 8 次插入1 次删除
  1. 1 1
      client/components/users/userAvatar.jade
  2. 7 0
      client/components/users/userAvatar.js

+ 1 - 1
client/components/users/userAvatar.jade

@@ -1,7 +1,7 @@
 template(name="userAvatar")
   a.member.js-member(title="{{userData.profile.fullname}} ({{userData.username}})")
     if userData.profile.avatarUrl
-      img.avatar.avatar-image(src=userData.profile.avatarUrl)
+      img.avatar.avatar-image(src="{{fixAvatarUrl userData.profile.avatarUrl}}")
     else
       +userAvatarInitials(userId=userData._id)
 

+ 7 - 0
client/components/users/userAvatar.js

@@ -14,6 +14,13 @@ Template.userAvatar.helpers({
     });
   },
 
+  fixAvatarUrl(avatarUrl) {
+    // Remove suburl from beginning of avatar file path,
+    // so that avatar images don't get broken when root-url changes to different sub-url.
+    avatarUrl = '/' + avatarUrl.substring(avatarUrl.indexOf('/cfs/files/avatars/')+1);
+    return avatarUrl;
+  },
+
   memberType() {
     const user = Users.findOne(this.userId);
     return user && user.isBoardAdmin() ? 'admin' : 'normal';