0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-25 21:24:34 +01:00

slight optimization for default avatar (#18187)

* slight optimization

* Update comment

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Lunny Xiao 2022-01-05 14:00:32 +08:00 committed by GitHub
parent ec6cc38c6c
commit 6da078d616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
@ -31,16 +32,24 @@ func init() {
db.RegisterModel(new(EmailHash))
}
var (
defaultAvatarLink string
once sync.Once
)
// DefaultAvatarLink the default avatar link
func DefaultAvatarLink() string {
u, err := url.Parse(setting.AppSubURL)
if err != nil {
log.Error("GetUserByEmail: %v", err)
return ""
}
once.Do(func() {
u, err := url.Parse(setting.AppSubURL)
if err != nil {
log.Error("Can not parse AppSubURL: %v", err)
return
}
u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
return u.String()
u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
defaultAvatarLink = u.String()
})
return defaultAvatarLink
}
// HashEmail hashes email address to MD5 string. https://en.gravatar.com/site/implement/hash/