Chore: fix go.mod and slugify after merge (#59611)

This commit is contained in:
Ryan McKinley
2022-11-30 13:16:57 -08:00
committed by GitHub
parent b4b843be66
commit b0b74337f1
4 changed files with 26 additions and 31 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/slugify"
"github.com/grafana/grafana/pkg/services/grpcserver"
"github.com/grafana/grafana/pkg/services/sqlstore/session"
"github.com/grafana/grafana/pkg/services/store"
@@ -305,7 +306,12 @@ func (s *sqlObjectServer) AdminWrite(ctx context.Context, r *object.AdminWriteOb
return nil, err
}
slug := slugifyTitle(summary.name, r.GRN.UID)
t := summary.name
if t == "" {
t = r.GRN.UID
}
slug := slugify.Slugify(t)
etag := createContentsHash(body)
rsp := &object.WriteObjectResponse{
GRN: grn,

View File

@@ -2,32 +2,10 @@ package sqlstash
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"strings"
"github.com/gosimple/slug"
)
func createContentsHash(contents []byte) string {
hash := md5.Sum(contents)
return hex.EncodeToString(hash[:])
}
func slugifyTitle(title string, fallback string) string {
if title == "" {
title = fallback
}
s := slug.Make(strings.ToLower(title))
if s == "" {
// If the dashboard name is only characters outside of the
// sluggable characters, the slug creation will return an
// empty string which will mess up URLs. This failsafe picks
// that up and creates the slug as a base64 identifier instead.
s = base64.RawURLEncoding.EncodeToString([]byte(title))
if slug.MaxLength != 0 && len(s) > slug.MaxLength {
s = s[:slug.MaxLength]
}
}
return s
}