Redesign UserMenu, now with support for Gravatar

This commit is contained in:
Deluan
2020-11-13 00:40:01 -05:00
parent 7efc32d136
commit 9d7995fd4d
7 changed files with 196 additions and 9 deletions
+25
View File
@@ -0,0 +1,25 @@
package gravatar
import (
"crypto/md5"
"fmt"
"strings"
"github.com/deluan/navidrome/utils"
)
const baseUrl = "https://www.gravatar.com/avatar"
const defaultSize = 80
const maxSize = 2048
func Url(email string, size int) string {
email = strings.ToLower(email)
email = strings.TrimSpace(email)
hash := md5.Sum([]byte(email))
if size < 1 {
size = defaultSize
}
size = utils.MinInt(maxSize, size)
return fmt.Sprintf("%s/%x?s=%d", baseUrl, hash, size)
}