diff --git a/config.yml.sample b/config.yml.sample
index 8affea75..fb430ede 100644
--- a/config.yml.sample
+++ b/config.yml.sample
@@ -30,8 +30,6 @@ service:
timezone: GMT
# Whether task comments should be enabled or not
enabletaskcomments: true
- # The duration in seconds until a cached gravatar user avatar expires
- gravatarexpiration: 3600
database:
# Database type to use. Supported types are mysql, postgres and sqlite.
@@ -154,3 +152,11 @@ migration:
# with the code obtained from the wunderlist api.
# Note that the vikunja frontend expects this to be /migrate/wunderlist
redirecturl:
+
+avatar:
+ # Switch between avatar providers. Possible values are gravatar and default.
+ # gravatar will fetch the avatar based on the user email.
+ # default will return a default avatar for every request.
+ provider: gravatar
+ # When using gravatar, this is the duration in seconds until a cached gravatar user avatar expires
+ gravatarexpiration: 3600
diff --git a/docs/content/doc/setup/config.md b/docs/content/doc/setup/config.md
index 923c005d..c78dedc4 100644
--- a/docs/content/doc/setup/config.md
+++ b/docs/content/doc/setup/config.md
@@ -73,8 +73,6 @@ service:
timezone: GMT
# Whether task comments should be enabled or not
enabletaskcomments: true
- # The duration in seconds until a cached gravatar user avatar expires
- gravatarexpiration: 3600
database:
# Database type to use. Supported types are mysql, postgres and sqlite.
@@ -197,4 +195,12 @@ migration:
# with the code obtained from the wunderlist api.
# Note that the vikunja frontend expects this to be /migrate/wunderlist
redirecturl:
+
+avatar:
+ # Switch between avatar providers. Possible values are gravatar and default.
+ # gravatar will fetch the avatar based on the user email.
+ # default will return a default avatar for every request.
+ provider: gravatar
+ # When using gravatar, this is the duration in seconds until a cached gravatar user avatar expires
+ gravatarexpiration: 3600
{{< /highlight >}}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 98f4d41f..9577b2d8 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -46,7 +46,6 @@ const (
ServiceEnableTaskAttachments Key = `service.enabletaskattachments`
ServiceTimeZone Key = `service.timezone`
ServiceEnableTaskComments Key = `service.enabletaskcomments`
- ServiceGravatarExpiration Key = `service.gravatarexpiration`
DatabaseType Key = `database.type`
DatabaseHost Key = `database.host`
@@ -103,6 +102,9 @@ const (
CorsEnable Key = `cors.enable`
CorsOrigins Key = `cors.origins`
CorsMaxAge Key = `cors.maxage`
+
+ AvatarProvider Key = `avatar.provider`
+ AvatarGravaterExpiration Key = `avatar.gravatarexpiration`
)
// GetString returns a string config value
@@ -174,7 +176,6 @@ func InitDefaultConfig() {
ServiceEnableTaskAttachments.setDefault(true)
ServiceTimeZone.setDefault("GMT")
ServiceEnableTaskComments.setDefault(true)
- ServiceGravatarExpiration.setDefault(3600)
// Database
DatabaseType.setDefault("sqlite")
@@ -230,6 +231,9 @@ func InitDefaultConfig() {
CorsMaxAge.setDefault(0)
// Migration
MigrationWunderlistEnable.setDefault(false)
+ // Avatar
+ AvatarProvider.setDefault("gravatar")
+ AvatarGravaterExpiration.setDefault(3600)
}
// InitConfig initializes the config, sets defaults etc.
diff --git a/pkg/modules/avatar/empty/empty.go b/pkg/modules/avatar/empty/empty.go
new file mode 100644
index 00000000..33f928cf
--- /dev/null
+++ b/pkg/modules/avatar/empty/empty.go
@@ -0,0 +1,45 @@
+// Vikunja is a to-do list application to facilitate your life.
+// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+package empty
+
+import "code.vikunja.io/api/pkg/user"
+
+// Provider represents the empty avatar provider
+type Provider struct {
+}
+
+const defaultAvatar string = `
+`
+
+// GetAvatar implements getting the avatar method
+func (p *Provider) GetAvatar(user *user.User, size int64) (avatar []byte, mimeType string, err error) {
+ return []byte(defaultAvatar), "image/svg+xml", nil
+}
diff --git a/pkg/modules/avatar/gravatar/gravatar.go b/pkg/modules/avatar/gravatar/gravatar.go
index 737e06ba..075df0a0 100644
--- a/pkg/modules/avatar/gravatar/gravatar.go
+++ b/pkg/modules/avatar/gravatar/gravatar.go
@@ -53,7 +53,7 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error
// elaped is alway < 0 so the next check would always succeed.
// To have it make sense, we flip that.
elapsed := time.Until(a.loadedAt) * -1
- needsRefetch = elapsed > time.Duration(config.ServiceGravatarExpiration.GetInt64())*time.Second
+ needsRefetch = elapsed > time.Duration(config.AvatarGravaterExpiration.GetInt64())*time.Second
if needsRefetch {
log.Debugf("Refetching avatar for user %d after %v", user.ID, elapsed)
} else {
diff --git a/pkg/routes/api/v1/avatar.go b/pkg/routes/api/v1/avatar.go
index 429d440c..f0b02f44 100644
--- a/pkg/routes/api/v1/avatar.go
+++ b/pkg/routes/api/v1/avatar.go
@@ -17,7 +17,10 @@
package v1
import (
+ "code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
+ "code.vikunja.io/api/pkg/modules/avatar"
+ "code.vikunja.io/api/pkg/modules/avatar/empty"
"code.vikunja.io/api/pkg/modules/avatar/gravatar"
user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web/handler"
@@ -51,7 +54,13 @@ func GetAvatar(c echo.Context) error {
// Initialize the avatar provider
// For now, we only have one avatar provider, in the future there could be multiple which
// could be changed based on user settings etc.
- avatarProvider := gravatar.Provider{}
+ var avatarProvider avatar.Provider
+ switch config.AvatarProvider.GetString() {
+ case "gravatar":
+ avatarProvider = &gravatar.Provider{}
+ default:
+ avatarProvider = &empty.Provider{}
+ }
size := c.QueryParam("size")
var sizeInt int64 = 250 // Default size of 250
@@ -64,11 +73,11 @@ func GetAvatar(c echo.Context) error {
}
// Get the avatar
- avatar, mimeType, err := avatarProvider.GetAvatar(user, sizeInt)
+ a, mimeType, err := avatarProvider.GetAvatar(user, sizeInt)
if err != nil {
log.Errorf("Error getting avatar for user %d: %v", user.ID, err)
return handler.HandleHTTPError(err, c)
}
- return c.Blob(http.StatusOK, mimeType, avatar)
+ return c.Blob(http.StatusOK, mimeType, a)
}