Add proxying gravatar requests for user avatars #148
|
@ -30,6 +30,8 @@ service:
|
||||||
timezone: GMT
|
timezone: GMT
|
||||||
# Whether task comments should be enabled or not
|
# Whether task comments should be enabled or not
|
||||||
enabletaskcomments: true
|
enabletaskcomments: true
|
||||||
|
# The duration in seconds until a cached gravatar user avatar expires
|
||||||
|
gravatarexpiration: 3600
|
||||||
|
|
||||||
database:
|
database:
|
||||||
# Database type to use. Supported types are mysql, postgres and sqlite.
|
# Database type to use. Supported types are mysql, postgres and sqlite.
|
||||||
|
|
|
@ -73,6 +73,8 @@ service:
|
||||||
timezone: GMT
|
timezone: GMT
|
||||||
# Whether task comments should be enabled or not
|
# Whether task comments should be enabled or not
|
||||||
enabletaskcomments: true
|
enabletaskcomments: true
|
||||||
|
# The duration in seconds until a cached gravatar user avatar expires
|
||||||
|
gravatarexpiration: 3600
|
||||||
|
|
||||||
database:
|
database:
|
||||||
# Database type to use. Supported types are mysql, postgres and sqlite.
|
# Database type to use. Supported types are mysql, postgres and sqlite.
|
||||||
|
|
|
@ -46,6 +46,7 @@ const (
|
||||||
ServiceEnableTaskAttachments Key = `service.enabletaskattachments`
|
ServiceEnableTaskAttachments Key = `service.enabletaskattachments`
|
||||||
ServiceTimeZone Key = `service.timezone`
|
ServiceTimeZone Key = `service.timezone`
|
||||||
ServiceEnableTaskComments Key = `service.enabletaskcomments`
|
ServiceEnableTaskComments Key = `service.enabletaskcomments`
|
||||||
|
ServiceGravatarExpiration Key = `service.gravatarexpiration`
|
||||||
|
|
||||||
DatabaseType Key = `database.type`
|
DatabaseType Key = `database.type`
|
||||||
DatabaseHost Key = `database.host`
|
DatabaseHost Key = `database.host`
|
||||||
|
@ -173,6 +174,7 @@ func InitDefaultConfig() {
|
||||||
ServiceEnableTaskAttachments.setDefault(true)
|
ServiceEnableTaskAttachments.setDefault(true)
|
||||||
ServiceTimeZone.setDefault("GMT")
|
ServiceTimeZone.setDefault("GMT")
|
||||||
ServiceEnableTaskComments.setDefault(true)
|
ServiceEnableTaskComments.setDefault(true)
|
||||||
|
ServiceGravatarExpiration.setDefault(3600)
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
DatabaseType.setDefault("sqlite")
|
DatabaseType.setDefault("sqlite")
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package gravatar
|
package gravatar
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -51,7 +52,7 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error
|
||||||
// elaped is alway < 0 so the next check would always succeed.
|
// elaped is alway < 0 so the next check would always succeed.
|
||||||
// To have it make sense, we flip that.
|
// To have it make sense, we flip that.
|
||||||
elapsed := a.loadedAt.Sub(time.Now()) * -1
|
elapsed := a.loadedAt.Sub(time.Now()) * -1
|
||||||
needsRefetch = elapsed > 10*time.Second
|
needsRefetch = elapsed > time.Duration(config.ServiceGravatarExpiration.GetInt64())*time.Second
|
||||||
if needsRefetch {
|
if needsRefetch {
|
||||||
log.Debugf("Refetching avatar for user %d after %v", user.ID, elapsed)
|
log.Debugf("Refetching avatar for user %d after %v", user.ID, elapsed)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue