mirror of
https://github.com/photoprism/photoprism.git
synced 2025-09-26 21:01:58 +08:00
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -33,6 +33,15 @@ func TypeLowerUnderscore(s string) string {
|
||||
return strings.ReplaceAll(TypeLower(s), " ", "_")
|
||||
}
|
||||
|
||||
// TypeLowerDash converts a string to a lowercase type string and replaces spaces with dashes.
|
||||
func TypeLowerDash(s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(TypeLower(s), " ", "-")
|
||||
}
|
||||
|
||||
// ShortType omits invalid runes, ensures a maximum length of 8 characters, and returns the result.
|
||||
func ShortType(s string) string {
|
||||
if s == "" {
|
||||
|
@@ -82,6 +82,24 @@ func TestTypeLowerUnderscore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTypeLowerDash(t *testing.T) {
|
||||
t.Run("Undefined", func(t *testing.T) {
|
||||
assert.Equal(t, "", TypeLowerDash(" \t "))
|
||||
})
|
||||
t.Run("ClientCredentials", func(t *testing.T) {
|
||||
assert.Equal(t, "client-credentials", TypeLowerDash(" Client Credentials幸"))
|
||||
})
|
||||
t.Run("OllamaModel", func(t *testing.T) {
|
||||
assert.Equal(
|
||||
t,
|
||||
"ollama-model:7b",
|
||||
TypeLowerDash("Ollama Model:7b"))
|
||||
})
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
assert.Equal(t, "", TypeLowerDash(""))
|
||||
})
|
||||
}
|
||||
|
||||
func TestShortType(t *testing.T) {
|
||||
t.Run("Clip", func(t *testing.T) {
|
||||
result := ShortType(" 幸福 Hanzi are logograms developed for the writing of Chinese! Expressions in an index may not ...!")
|
||||
|
@@ -45,6 +45,18 @@ func DataUrl(r io.Reader) string {
|
||||
return fmt.Sprintf("data:%s;base64,%s", mimeType, EncodeBase64String(data))
|
||||
}
|
||||
|
||||
// DataBase64 generates a base64 encoded string of the binary data from the specified io.Reader.
|
||||
func DataBase64(r io.Reader) string {
|
||||
// Read binary data.
|
||||
data, err := io.ReadAll(r)
|
||||
|
||||
if err != nil || len(data) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return EncodeBase64String(data)
|
||||
}
|
||||
|
||||
// ReadUrl reads binary data from a regular file path,
|
||||
// fetches its data from a remote http or https URL,
|
||||
// or decodes a base64 data URL as created by DataUrl.
|
||||
|
@@ -6,6 +6,7 @@ type Type = string
|
||||
const (
|
||||
File Type = "file"
|
||||
Data Type = "data"
|
||||
Base64 Type = "base64"
|
||||
Http Type = "http"
|
||||
Https Type = "https"
|
||||
Websocket Type = "wss"
|
||||
|
Reference in New Issue
Block a user