MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / validateAnnouncements

Function validateAnnouncements

setting/console_setting/validation.go:141–185  ·  view source on GitHub ↗
(announcementsStr string)

Source from the content-addressed store, hash-verified

139}
140
141func validateAnnouncements(announcementsStr string) error {
142 list, err := parseJSONArray(announcementsStr, "系统公告")
143 if err != nil {
144 return err
145 }
146 if len(list) > 100 {
147 return fmt.Errorf("系统公告数量不能超过100个")
148 }
149 validTypes := map[string]bool{
150 "default": true, "ongoing": true, "success": true, "warning": true, "error": true,
151 }
152 for i, ann := range list {
153 content, ok := ann["content"].(string)
154 if !ok || content == "" {
155 return fmt.Errorf("第%d个公告缺少内容字段", i+1)
156 }
157 publishDateAny, exists := ann["publishDate"]
158 if !exists {
159 return fmt.Errorf("第%d个公告缺少发布日期字段", i+1)
160 }
161 publishDateStr, ok := publishDateAny.(string)
162 if !ok || publishDateStr == "" {
163 return fmt.Errorf("第%d个公告的发布日期不能为空", i+1)
164 }
165 if _, err := time.Parse(time.RFC3339, publishDateStr); err != nil {
166 return fmt.Errorf("第%d个公告的发布日期格式错误", i+1)
167 }
168 if t, exists := ann["type"]; exists {
169 if typeStr, ok := t.(string); ok {
170 if !validTypes[typeStr] {
171 return fmt.Errorf("第%d个公告的类型值不合法", i+1)
172 }
173 }
174 }
175 if len(content) > 500 {
176 return fmt.Errorf("第%d个公告的内容长度不能超过500字符", i+1)
177 }
178 if extra, exists := ann["extra"]; exists {
179 if extraStr, ok := extra.(string); ok && len(extraStr) > 200 {
180 return fmt.Errorf("第%d个公告的说明长度不能超过200字符", i+1)
181 }
182 }
183 }
184 return nil
185}
186
187func validateFAQ(faqStr string) error {
188 list, err := parseJSONArray(faqStr, "FAQ信息")

Callers 1

ValidateConsoleSettingsFunction · 0.85

Calls 1

parseJSONArrayFunction · 0.85

Tested by

no test coverage detected