Send size to /avatars if requested (#15459)
If an avatar is requested in a particular size ensure that /avatars also gets the size request Fix #15453 Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
c29620c05f
commit
324cff68c9
2 changed files with 11 additions and 3 deletions
|
@ -81,7 +81,7 @@ func LibravatarURL(email string) (*url.URL, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashedAvatarLink returns an avatar link for a provided email
|
// HashedAvatarLink returns an avatar link for a provided email
|
||||||
func HashedAvatarLink(email string) string {
|
func HashedAvatarLink(email string, size int) string {
|
||||||
lowerEmail := strings.ToLower(strings.TrimSpace(email))
|
lowerEmail := strings.ToLower(strings.TrimSpace(email))
|
||||||
sum := fmt.Sprintf("%x", md5.Sum([]byte(lowerEmail)))
|
sum := fmt.Sprintf("%x", md5.Sum([]byte(lowerEmail)))
|
||||||
_, _ = cache.GetString("Avatar:"+sum, func() (string, error) {
|
_, _ = cache.GetString("Avatar:"+sum, func() (string, error) {
|
||||||
|
@ -108,6 +108,9 @@ func HashedAvatarLink(email string) string {
|
||||||
}
|
}
|
||||||
return lowerEmail, nil
|
return lowerEmail, nil
|
||||||
})
|
})
|
||||||
|
if size > 0 {
|
||||||
|
return setting.AppSubURL + "/avatar/" + url.PathEscape(sum) + "?size=" + strconv.Itoa(size)
|
||||||
|
}
|
||||||
return setting.AppSubURL + "/avatar/" + url.PathEscape(sum)
|
return setting.AppSubURL + "/avatar/" + url.PathEscape(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +132,7 @@ func SizedAvatarLink(email string, size int) string {
|
||||||
// This is the slow path that would need to call LibravatarURL() which
|
// This is the slow path that would need to call LibravatarURL() which
|
||||||
// does DNS lookups. Avoid it by issuing a redirect so we don't block
|
// does DNS lookups. Avoid it by issuing a redirect so we don't block
|
||||||
// the template render with network requests.
|
// the template render with network requests.
|
||||||
return HashedAvatarLink(email)
|
return HashedAvatarLink(email, size)
|
||||||
} else if !setting.DisableGravatar {
|
} else if !setting.DisableGravatar {
|
||||||
// copy GravatarSourceURL, because we will modify its Path.
|
// copy GravatarSourceURL, because we will modify its Path.
|
||||||
copyOfGravatarSourceURL := *setting.GravatarSourceURL
|
copyOfGravatarSourceURL := *setting.GravatarSourceURL
|
||||||
|
|
|
@ -82,6 +82,9 @@ func (u *User) RealSizedAvatarLink(size int) string {
|
||||||
if u.Avatar == "" {
|
if u.Avatar == "" {
|
||||||
return DefaultAvatarLink()
|
return DefaultAvatarLink()
|
||||||
}
|
}
|
||||||
|
if size > 0 {
|
||||||
|
return setting.AppSubURL + "/avatars/" + u.Avatar + "?size=" + strconv.Itoa(size)
|
||||||
|
}
|
||||||
return setting.AppSubURL + "/avatars/" + u.Avatar
|
return setting.AppSubURL + "/avatars/" + u.Avatar
|
||||||
case setting.DisableGravatar, setting.OfflineMode:
|
case setting.DisableGravatar, setting.OfflineMode:
|
||||||
if u.Avatar == "" {
|
if u.Avatar == "" {
|
||||||
|
@ -89,7 +92,9 @@ func (u *User) RealSizedAvatarLink(size int) string {
|
||||||
log.Error("GenerateRandomAvatar: %v", err)
|
log.Error("GenerateRandomAvatar: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if size > 0 {
|
||||||
|
return setting.AppSubURL + "/avatars/" + u.Avatar + "?size=" + strconv.Itoa(size)
|
||||||
|
}
|
||||||
return setting.AppSubURL + "/avatars/" + u.Avatar
|
return setting.AppSubURL + "/avatars/" + u.Avatar
|
||||||
}
|
}
|
||||||
return SizedAvatarLink(u.AvatarEmail, size)
|
return SizedAvatarLink(u.AvatarEmail, size)
|
||||||
|
|
Reference in a new issue