diff options
author | Sandro Santilli <strk@kbt.io> | 2019-09-26 18:21:23 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-09-26 12:21:23 -0400 |
commit | d958b9db4fa0f1910b3ca82338e3d68a70efedd9 (patch) | |
tree | 9f2de2fd82eed04ac8ed5cc26771824ba4648506 /models | |
parent | b2b927808b201eef44ef26be7d8529c315fcd170 (diff) | |
download | gitea-d958b9db4fa0f1910b3ca82338e3d68a70efedd9.tar.gz gitea-d958b9db4fa0f1910b3ca82338e3d68a70efedd9.zip |
Alwaywas return local url for users avatar (#8245)
* Always return local url for users avatar
Avoids having to wait for DNS lookups when libravatar is activated
fixing #6046
* Avoid double slash in avatar link
* Move avatar route to the correct place
Diffstat (limited to 'models')
-rw-r--r-- | models/action_test.go | 2 | ||||
-rw-r--r-- | models/user.go | 16 |
2 files changed, 15 insertions, 3 deletions
diff --git a/models/action_test.go b/models/action_test.go index 16fdc7adcc..c90538ebe6 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -173,7 +173,7 @@ func TestPushCommits_AvatarLink(t *testing.T) { pushCommits.Len = len(pushCommits.Commits) assert.Equal(t, - "https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?d=identicon", + "/suburl/user/avatar/user2/-1", pushCommits.AvatarLink("user2@example.com")) assert.Equal(t, diff --git a/models/user.go b/models/user.go index e31f8b8534..030e23c383 100644 --- a/models/user.go +++ b/models/user.go @@ -17,6 +17,7 @@ import ( "image/png" "os" "path/filepath" + "strconv" "strings" "time" "unicode/utf8" @@ -374,9 +375,20 @@ func (u *User) generateRandomAvatar(e Engine) error { return nil } -// SizedRelAvatarLink returns a relative link to the user's avatar. When -// applicable, the link is for an avatar of the indicated size (in pixels). +// SizedRelAvatarLink returns a link to the user's avatar via +// the local explore page. Function returns immediately. +// When applicable, the link is for an avatar of the indicated size (in pixels). func (u *User) SizedRelAvatarLink(size int) string { + return strings.TrimRight(setting.AppSubURL, "/") + "/user/avatar/" + u.Name + "/" + strconv.Itoa(size) +} + +// RealSizedAvatarLink returns a link to the user's avatar. When +// applicable, the link is for an avatar of the indicated size (in pixels). +// +// This function make take time to return when federated avatars +// are in use, due to a DNS lookup need +// +func (u *User) RealSizedAvatarLink(size int) string { if u.ID == -1 { return base.DefaultAvatarLink() } |