Browse Source

Merge pull request #716 from ErebusBat/master

Fix Gravatar images in web view (like commit listing)
pull/718/head
无闻 10 years ago
parent
commit
298ebc58c1
  1. 6
      modules/avatar/avatar.go
  2. 10
      modules/base/tool.go

6
modules/avatar/avatar.go

@ -48,8 +48,12 @@ func init() {
// hash email to md5 string
// keep this func in order to make this package indenpent
func HashEmail(email string) string {
// https://en.gravatar.com/site/implement/hash/
email = strings.TrimSpace(email)
email = strings.ToLower(email)
h := md5.New()
h.Write([]byte(strings.ToLower(email)))
h.Write([]byte(email))
return hex.EncodeToString(h.Sum(nil))
}

10
modules/base/tool.go

@ -23,6 +23,7 @@ import (
"github.com/Unknwon/com"
"github.com/Unknwon/i18n"
"github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/setting"
)
@ -177,10 +178,13 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
func AvatarLink(email string) string {
if setting.DisableGravatar {
return setting.AppSubUrl + "/img/avatar_default.jpg"
} else if setting.Service.EnableCacheAvatar {
return setting.AppSubUrl + "/avatar/" + EncodeMd5(email)
}
return setting.GravatarSource + EncodeMd5(email)
gravatarHash := avatar.HashEmail(email)
if setting.Service.EnableCacheAvatar {
return setting.AppSubUrl + "/avatar/" + gravatarHash
}
return setting.GravatarSource + gravatarHash
}
// Seconds-based time units

Loading…
Cancel
Save