<commit_before>package dtos

import (
	"crypto/md5"
	"fmt"
	"regexp"
	"strings"

	"github.com/grafana/grafana/pkg/components/simplejson"
	m "github.com/grafana/grafana/pkg/models"
	"github.com/grafana/grafana/pkg/setting"
)

type AnyId struct {
	Id int64 `json:"id"`
}

type LoginCommand struct {
	User     string `json:"user" binding:"Required"`
	Password string `json:"password" binding:"Required"`
	Remember bool   `json:"remember"`
}

type CurrentUser struct {
	IsSignedIn                 bool         `json:"isSignedIn"`
	Id                         int64        `json:"id"`
	Login                      string       `json:"login"`
	Email                      string       `json:"email"`
	Name                       string       `json:"name"`
	LightTheme                 bool         `json:"lightTheme"`
	OrgCount                   int          `json:"orgCount"`
	OrgId                      int64        `json:"orgId"`
	OrgName                    string       `json:"orgName"`
	OrgRole                    m.RoleType   `json:"orgRole"`
	IsGrafanaAdmin             bool         `json:"isGrafanaAdmin"`
	GravatarUrl                string       `json:"gravatarUrl"`
	Timezone                   string       `json:"timezone"`
	Locale                     string       `json:"locale"`
	HelpFlags1                 m.HelpFlags1 `json:"helpFlags1"`
	HasEditPermissionInFolders bool         `json:"hasEditPermissionInFolders"`
}

type MetricRequest struct {
	From    string             `json:"from"`
	To      string             `json:"to"`
	Queries []*simplejson.Json `json:"queries"`
}

type UserStars struct {
	DashboardIds map[string]bool `json:"dashboardIds"`
}

func GetGravatarUrl(text string) string {
	if setting.DisableGravatar {
		return "/public/img/user_profile.png"
	}

	if text == "" {
		return ""
	}

	hasher := md5.New()
	hasher.Write([]byte(strings.ToLower(text)))
	return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
}

func GetGravatarUrlWithDefault(text string, defaultText string) string {
	if text != "" {
		return GetGravatarUrl(text)
	}

	reg, err := regexp.Compile("[^a-zA-Z0-9]+")

	if err != nil {
		return ""
	}

	text = reg.ReplaceAllString(defaultText, "") + "@localhost"

	return GetGravatarUrl(text)<commit_msg>Gravatar fallback does not respect 'AppSubUrl'-setting (#12149)<commit_after>package dtos

import (
	"crypto/md5"
	"fmt"
	"regexp"
	"strings"

	"github.com/grafana/grafana/pkg/components/simplejson"
	m "github.com/grafana/grafana/pkg/models"
	"github.com/grafana/grafana/pkg/setting"
)

type AnyId struct {
	Id int64 `json:"id"`
}

type LoginCommand struct {
	User     string `json:"user" binding:"Required"`
	Password string `json:"password" binding:"<PASSWORD>"`
	Remember bool   `json:"remember"`
}

type CurrentUser struct {
	IsSignedIn                 bool         `json:"isSignedIn"`
	Id                         int64        `json:"id"`
	Login                      string       `json:"login"`
	Email                      string       `json:"email"`
	Name                       string       `json:"name"`
	LightTheme                 bool         `json:"lightTheme"`
	OrgCount                   int          `json:"orgCount"`
	OrgId                      int64        `json:"orgId"`
	OrgName                    string       `json:"orgName"`
	OrgRole                    m.RoleType   `json:"orgRole"`
	IsGrafanaAdmin             bool         `json:"isGrafanaAdmin"`
	GravatarUrl                string       `json:"gravatarUrl"`
	Timezone                   string       `json:"timezone"`
	Locale                     string       `json:"locale"`
	HelpFlags1                 m.HelpFlags1 `json:"helpFlags1"`
	HasEditPermissionInFolders bool         `json:"hasEditPermissionInFolders"`
}

type MetricRequest struct {
	From    string             `json:"from"`
	To      string             `json:"to"`
	Queries []*simplejson.Json `json:"queries"`
}

type UserStars struct {
	DashboardIds map[string]bool `json:"dashboardIds"`
}

func GetGravatarUrl(text string) string {
	if setting.DisableGravatar {
		return setting.AppSubUrl + "/public/img/user_profile.png"
	}

	if text == "" {
		return ""
	}

	hasher := md5.New()
	hasher.Write([]byte(strings.ToLower(text)))
	return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
}

func GetGravatarUrlWithDefault(text string, defaultText string) string {
	if text != "" {
		return GetGravatarUrl(text)
	}

	reg, err := regexp.Compile("[^a-zA-Z0-9]+")

	if err != nil {
		return ""
	}

	text = reg.ReplaceAllString(defaultText, "") + "@localhost"

	return GetGravatarUrl(text)
{'fraction_non_alphanumeric': 0.12286838653257542, 'fraction_numerical': 0.006777437691298645, 'mean_word_length': 2.270192994996426, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5683433', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1405, 'n_words': 284}