/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
pkg/clean/thumb.go
42 строки
812 B
Michael Mayer
API: Update Thumb/ThumbSrc for subjects and labels #4151
04 окт 2025, 00:17
04 окт 2025, 00:17
d7ee54e
Код
Авторство
О чём код?
package clean import "strings" // Thumb returns a sanitized thumbnail hash (40 hex characters) or an empty string when invalid. func Thumb(s string) string { s = strings.TrimSpace(s) if len(s) != 40 { return "" } if h := Hex(s); len(h) == 40 { return h } return "" } // ThumbCrop returns a sanitized thumbnail crop hash (`hash-area`) or an empty string when invalid. // Cropped thumbnails combine the base hash with a 12-hex crop descriptor separated by a dash. func ThumbCrop(s string) string { s = strings.TrimSpace(s) if len(s) < 41 { return "" } if i := strings.IndexByte(s, '-'); i == -1 || i < 40 || i >= len(s)-1 { return "" } else { h := Thumb(s[:i]) if h == "" { return "" } crop := Hex(s[i+1:]) if len(crop) != 12 { return "" } return h + "-" + crop } }