photoprism/pkg/rnd/uuid.go
Michael Mayer 91a1a1ca27 Backend: Ignore image unique IDs that are not standard UUIDs
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-07-23 15:34:20 +02:00

36 lines
626 B
Go

package rnd
import (
"strings"
uuid "github.com/satori/go.uuid"
)
// UUID returns a standard, random UUID as string.
func UUID() string {
return uuid.NewV4().String()
}
// Returns true if the string looks like a standard UUID.
func IsUUID(s string) bool {
return len(s) == 36 && IsHex(s)
}
// SanitizeUUID normalizes UUIDs found in XMP or Exif metadata.
func SanitizeUUID(s string) string {
if s == "" {
return ""
}
s = strings.Replace(strings.TrimSpace(s), "\"", "", -1)
if start := strings.LastIndex(s, ":"); start != -1 {
s = s[start+1:]
}
if !IsUUID(s) {
return ""
}
return strings.ToLower(s)
}