Browse Source

Merge branch 'fix-323' of https://git.openi.org.cn/OpenI/aiforge into fix-323

tags/v1.22.4.1^2
Gitea 3 years ago
parent
commit
aba9e6227c
4 changed files with 38 additions and 2 deletions
  1. +27
    -0
      models/cloudbrain_image.go
  2. +1
    -0
      options/locale/locale_en-US.ini
  3. +1
    -0
      options/locale/locale_zh-CN.ini
  4. +9
    -2
      routers/repo/cloudbrain.go

+ 27
- 0
models/cloudbrain_image.go View File

@@ -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 {


+ 1
- 0
options/locale/locale_en-US.ini View File

@@ -2147,6 +2147,7 @@ topic.manage_topics = Manage Topics
topic.done = Done
topic.count_prompt = You can not select more than 25 topics
topic.format_prompt = Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
imagetopic.format_prompt = Topics can be up to 35 characters long.

[org]
org_name_holder = Organization Name


+ 1
- 0
options/locale/locale_zh-CN.ini View File

@@ -2155,6 +2155,7 @@ topic.manage_topics=管理主题
topic.done=保存
topic.count_prompt=您最多选择25个标签
topic.format_prompt=标签必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
imagetopic.format_prompt=标签长度不得超过35个字符

[org]
org_name_holder=组织名称


+ 9
- 2
routers/repo/cloudbrain.go View File

@@ -586,11 +586,18 @@ func checkTopics(Topics string) ([]string, string) {
topics = strings.Split(topicsStr, ",")
}

if len(topics) > 25 {
validTopics, invalidTopics := models.SanitizeAndValidateImageTopics(topics)

if len(validTopics) > 25 {
return nil, "repo.topic.count_prompt"

}
return topics, ""

if len(invalidTopics) > 0 {
return nil, "repo.imagetopic.format_prompt"

}
return validTopics, ""
}

func CloudBrainStop(ctx *context.Context) {


Loading…
Cancel
Save