photoprism/pkg/s2/token_prefix.go
Michael Mayer 06d8816a7f Search: Improve location search filters and related docs #1187 #3558
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-09-20 12:10:49 +02:00

37 lines
749 B
Go

package s2
import (
"strings"
)
var TokenPrefix = "s2:"
// NormalizeToken removes the prefix from a token and converts all characters to lower case.
func NormalizeToken(token string) string {
token = strings.ToLower(token)
token = strings.TrimSpace(token)
if strings.HasPrefix(token, TokenPrefix) {
return token[len(TokenPrefix):]
}
return token
}
// Prefix adds a token prefix if not exists.
func Prefix(token string) string {
if len(token) < 3 {
return token
}
if strings.HasPrefix(token, TokenPrefix) {
return token
}
return TokenPrefix + token
}
// PrefixedToken returns the prefixed S2 cell token for coordinates using the default level.
func PrefixedToken(lat, lng float64) string {
return Prefix(Token(lat, lng))
}