MCPcopy Create free account
hub / github.com/gogs/gogs / AvatarURLPath

Method AvatarURLPath

internal/database/users.go:1373–1395  ·  view source on GitHub ↗

AvatarURLPath returns the URL path to the user or organization avatar. If the user enables Gravatar-like service, then an external URL will be returned. TODO(unknwon): This is also used in templates, which should be fixed by having a dedicated type `template.User` and move this to the "userutil" pa

()

Source from the content-addressed store, hash-verified

1371// having a dedicated type `template.User` and move this to the "userutil"
1372// package.
1373func (u *User) AvatarURLPath() string {
1374 defaultURLPath := conf.UserDefaultAvatarURLPath()
1375 if u.ID <= 0 {
1376 return defaultURLPath
1377 }
1378
1379 hasCustomAvatar := osutil.IsFile(userutil.CustomAvatarPath(u.ID))
1380 switch {
1381 case u.UseCustomAvatar:
1382 if !hasCustomAvatar {
1383 return defaultURLPath
1384 }
1385 return fmt.Sprintf("%s/%s/%d", conf.Server.Subpath, conf.UsersAvatarPathPrefix, u.ID)
1386 case conf.Picture.DisableGravatar:
1387 if !hasCustomAvatar {
1388 if err := userutil.GenerateRandomAvatar(u.ID, u.Name, u.Email); err != nil {
1389 log.Error("Failed to generate random avatar [user_id: %d]: %v", u.ID, err)
1390 }
1391 }
1392 return fmt.Sprintf("%s/%s/%d", conf.Server.Subpath, conf.UsersAvatarPathPrefix, u.ID)
1393 }
1394 return tool.AvatarLink(u.AvatarEmail)
1395}
1396
1397// AvatarURL returns the full URL to the user or organization avatar. If the
1398// user enables Gravatar-like service, then an external URL will be returned.

Callers 3

AvatarURLMethod · 0.95
AvatarLinkMethod · 0.80
retrieveFeedsFunction · 0.80

Implementers 1

mailerUserinternal/database/issue_mail.go

Calls 6

UserDefaultAvatarURLPathFunction · 0.92
IsFileFunction · 0.92
CustomAvatarPathFunction · 0.92
GenerateRandomAvatarFunction · 0.92
AvatarLinkFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected