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

Function validateApiInfo

setting/console_setting/validation.go:81–135  ·  view source on GitHub ↗
(apiInfoStr string)

Source from the content-addressed store, hash-verified

79}
80
81func validateApiInfo(apiInfoStr string) error {
82 apiInfoList, err := parseJSONArray(apiInfoStr, "API信息")
83 if err != nil {
84 return err
85 }
86
87 if len(apiInfoList) > 50 {
88 return fmt.Errorf("API信息数量不能超过50个")
89 }
90
91 for i, apiInfo := range apiInfoList {
92 urlStr, ok := apiInfo["url"].(string)
93 if !ok || urlStr == "" {
94 return fmt.Errorf("第%d个API信息缺少URL字段", i+1)
95 }
96 route, ok := apiInfo["route"].(string)
97 if !ok || route == "" {
98 return fmt.Errorf("第%d个API信息缺少线路描述字段", i+1)
99 }
100 description, ok := apiInfo["description"].(string)
101 if !ok || description == "" {
102 return fmt.Errorf("第%d个API信息缺少说明字段", i+1)
103 }
104 color, ok := apiInfo["color"].(string)
105 if !ok || color == "" {
106 return fmt.Errorf("第%d个API信息缺少颜色字段", i+1)
107 }
108
109 if err := validateURL(urlStr, i+1, "API信息"); err != nil {
110 return err
111 }
112
113 if len(urlStr) > 500 {
114 return fmt.Errorf("第%d个API信息的URL长度不能超过500字符", i+1)
115 }
116 if len(route) > 100 {
117 return fmt.Errorf("第%d个API信息的线路描述长度不能超过100字符", i+1)
118 }
119 if len(description) > 200 {
120 return fmt.Errorf("第%d个API信息的说明长度不能超过200字符", i+1)
121 }
122
123 if !validColors[color] {
124 return fmt.Errorf("第%d个API信息的颜色值不合法", i+1)
125 }
126
127 if err := checkDangerousContent(description, i+1, "API信息"); err != nil {
128 return err
129 }
130 if err := checkDangerousContent(route, i+1, "API信息"); err != nil {
131 return err
132 }
133 }
134 return nil
135}
136
137func GetApiInfo() []map[string]interface{} {
138 return getJSONList(GetConsoleSetting().ApiInfo)

Callers 1

ValidateConsoleSettingsFunction · 0.85

Calls 3

parseJSONArrayFunction · 0.85
validateURLFunction · 0.85
checkDangerousContentFunction · 0.85

Tested by

no test coverage detected