diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-10-25 13:01:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 13:01:16 +0800 |
commit | 7c951fdd4a9dc15313522ac27aacd687687ddafc (patch) | |
tree | 6866a5b49517903bbff56759d17784d4d6bd246d /models | |
parent | 3676fafdacaef7ef0a6b72be99a342f91c8d5e5d (diff) | |
download | gitea-7c951fdd4a9dc15313522ac27aacd687687ddafc.tar.gz gitea-7c951fdd4a9dc15313522ac27aacd687687ddafc.zip |
In many cases user avatar link should be an absolute URL with http host (#17420)
Diffstat (limited to 'models')
-rw-r--r-- | models/user_avatar.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/models/user_avatar.go b/models/user_avatar.go index b8296568c2..f96f66f930 100644 --- a/models/user_avatar.go +++ b/models/user_avatar.go @@ -9,6 +9,7 @@ import ( "fmt" "image/png" "io" + "strings" "code.gitea.io/gitea/models/avatars" "code.gitea.io/gitea/models/db" @@ -91,9 +92,13 @@ func (u *User) AvatarLinkWithSize(size int) string { return avatars.GenerateEmailAvatarFastLink(u.AvatarEmail, size) } -// AvatarLink returns a avatar link with default size +// AvatarLink returns the full avatar link with http host func (u *User) AvatarLink() string { - return u.AvatarLinkWithSize(0) + link := u.AvatarLinkWithSize(0) + if !strings.HasPrefix(link, "//") && !strings.Contains(link, "://") { + return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL+"/") + } + return link } // UploadAvatar saves custom avatar for user. |