feat: add configurable gravatar-compatible base URL (#2083)

This adds the ability to set a base URL for a Gravatar-compatible avatar
service (Gravatar itself, or Libravatar, for instance). The default will
be www.gravatar.com, so nothing will change from current behaviour unless
the user explicitly configures another URL.

Resolves #2082
This commit is contained in:
rhclayto
2026-01-13 06:58:08 -07:00
committed by GitHub
parent bdd3db68fb
commit c5969d9898
3 changed files with 14 additions and 1 deletions

View File

@@ -616,6 +616,11 @@
"key": "gravatarexpiration",
"default_value": "3600",
"comment": "When using gravatar, this is the duration in seconds until a cached gravatar user avatar expires"
},
{
"key": "gravatarbaseurl",
"default_value": "https://www.gravatar.com",
"comment": "If you use a Gravatar-compatible service other than gravatar.com, you may configure the base URL for the service here.\nFor instance, gravatarbaseurl: 'https://libravatar.org'. The default is https://www.gravatar.com."
}
]
},

View File

@@ -187,6 +187,7 @@ const (
CorsMaxAge Key = `cors.maxage`
AvatarGravaterExpiration Key = `avatar.gravatarexpiration`
AvatarGravatarBaseURL Key = `avatar.gravatarbaseurl`
BackgroundsEnabled Key = `backgrounds.enabled`
BackgroundsUploadEnabled Key = `backgrounds.providers.upload.enabled`
@@ -456,6 +457,7 @@ func InitDefaultConfig() {
MigrationMicrosoftTodoEnable.setDefault(false)
// Avatar
AvatarGravaterExpiration.setDefault(3600)
AvatarGravatarBaseURL.setDefault("https://www.gravatar.com")
// Project Backgrounds
BackgroundsEnabled.setDefault(true)
BackgroundsUploadEnabled.setDefault(true)
@@ -605,6 +607,12 @@ func InitConfig() {
readConfigValuesFromFiles()
if _, err := url.ParseRequestURI(AvatarGravatarBaseURL.GetString()); err != nil {
log.Fatalf("Could not parse gravatarbaseurl: %s", err)
}
AvatarGravatarBaseURL.Set(strings.TrimRight(AvatarGravatarBaseURL.GetString(), "/"))
if RateLimitStore.GetString() == "keyvalue" {
RateLimitStore.Set(KeyvalueType.GetString())
}

View File

@@ -86,7 +86,7 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error
}
log.Debugf("Gravatar for user %d with size %d not cached, requesting from gravatar...", user.ID, size)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://www.gravatar.com/avatar/"+utils.Md5String(strings.ToLower(user.Email))+"?s="+sizeString+"&d=mp", nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, config.AvatarGravatarBaseURL.GetString()+"/avatar/"+utils.Md5String(strings.ToLower(user.Email))+"?s="+sizeString+"&d=mp", nil)
if err != nil {
return nil, err
}