|
|
|
@@ -3,6 +3,7 @@ package models |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
"unicode/utf8" |
|
|
|
|
|
|
|
"xorm.io/builder" |
|
|
|
|
|
|
|
@@ -127,6 +128,32 @@ func GetImageByID(id int64) (*Image, error) { |
|
|
|
|
|
|
|
return rel, nil |
|
|
|
} |
|
|
|
|
|
|
|
func SanitizeAndValidateImageTopics(topics []string) (validTopics []string, invalidTopics []string) { |
|
|
|
validTopics = make([]string, 0) |
|
|
|
mValidTopics := make(map[string]struct{}) |
|
|
|
invalidTopics = make([]string, 0) |
|
|
|
|
|
|
|
for _, topic := range topics { |
|
|
|
topic = strings.TrimSpace(strings.ToLower(topic)) |
|
|
|
// ignore empty string |
|
|
|
if len(topic) == 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
// ignore same topic twice |
|
|
|
if _, ok := mValidTopics[topic]; ok { |
|
|
|
continue |
|
|
|
} |
|
|
|
if utf8.RuneCountInString(topic) <= 35 { |
|
|
|
validTopics = append(validTopics, topic) |
|
|
|
mValidTopics[topic] = struct{}{} |
|
|
|
} else { |
|
|
|
invalidTopics = append(invalidTopics, topic) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return validTopics, invalidTopics |
|
|
|
} |
|
|
|
func FindImageTopics(opts *FindImageTopicOptions) (topics []*ImageTopic, err error) { |
|
|
|
sess := x.Select("image_topic.*").Where(opts.toConds()) |
|
|
|
if opts.ImageID > 0 { |
|
|
|
|