photoprism/pkg/clean/state.go
Michael Mayer 92e6c4fe1e Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options:
- Name: File name pattern for downloaded files (existed)
- Disabled: Disables downloads
- Originals: Only download files stored in "originals" folder
- MediaRaw: Include RAW image files
- MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
2022-04-15 09:42:07 +02:00

54 lines
1.1 KiB
Go

package clean
import (
"strings"
"unicode"
"github.com/photoprism/photoprism/pkg/txt"
)
// State returns the full, normalized state name.
func State(s, countryCode string) string {
if s == "" || reject(s, txt.ClipName) {
return Empty
}
// Remove whitespace from name.
s = strings.TrimSpace(s)
// Empty?
if s == "" || s == txt.UnknownStateCode {
// State doesn't have a name.
return ""
}
// Remove non-printable and other potentially problematic characters.
s = strings.Map(func(r rune) rune {
if !unicode.IsPrint(r) {
return -1
}
switch r {
case '~', '\\', ':', '|', '"', '?', '*', '<', '>', '{', '}':
return -1
default:
return r
}
}, s)
// Normalize country code.
countryCode = strings.ToLower(strings.TrimSpace(countryCode))
// Is the name an abbreviation that should be normalized?
if states, found := txt.StatesByCountry[countryCode]; !found {
// Unknown country.
} else if normalized, found := states[s]; !found {
// Unknown abbreviation.
} else if normalized != "" {
// Yes, use normalized name.
s = normalized
}
// Return normalized state name.
return s
}