系统设置页面功能完成

This commit is contained in:
RockYang
2023-05-03 09:48:37 +08:00
parent 556abf5276
commit fcfe0c7913
6 changed files with 181 additions and 99 deletions

View File

@@ -19,8 +19,15 @@ func (s *Server) AddApiKeyHandle(c *gin.Context) {
c.JSON(http.StatusBadRequest, nil)
return
}
// 过滤已存在的 Key
for _,key:=range s.Config.Chat.ApiKeys {
if key.Value == data.ApiKey {
c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: "API KEY 已存在"})
return
}
}
if len(data.ApiKey) > 20 {
s.Config.Chat.ApiKeys = append(s.Config.Chat.ApiKeys, data.ApiKey)
s.Config.Chat.ApiKeys = append(s.Config.Chat.ApiKeys, types.APIKey{Value: data.ApiKey})
}
// 保存配置文件
@@ -46,8 +53,9 @@ func (s *Server) RemoveApiKeyHandle(c *gin.Context) {
}
for i, v := range s.Config.Chat.ApiKeys {
if v == data.ApiKey {
if v.Value == data.ApiKey {
s.Config.Chat.ApiKeys = append(s.Config.Chat.ApiKeys[:i], s.Config.Chat.ApiKeys[i+1:]...)
break
}
}