添加会话授权支持

This commit is contained in:
RockYang
2023-03-21 18:12:24 +08:00
parent 3bb6814493
commit 005d219a8c
16 changed files with 403 additions and 73 deletions

View File

@@ -10,6 +10,12 @@ import (
// ConfigSetHandle set configs
func (s *Server) ConfigSetHandle(c *gin.Context) {
token := c.Query("token")
if token != "RockYang" {
c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: types.ErrorMsg})
return
}
var data map[string]string
err := json.NewDecoder(c.Request.Body).Decode(&data)
if err != nil {
@@ -71,6 +77,23 @@ func (s *Server) ConfigSetHandle(c *gin.Context) {
s.Config.Chat.EnableContext = v
}
// enable auth
if enableAuth, ok := data["enable_auth"]; ok {
v, err := strconv.ParseBool(enableAuth)
if err != nil {
c.JSON(http.StatusOK, types.BizVo{
Code: types.InvalidParams,
Message: "enable_auth must be a bool parameter",
})
return
}
s.Config.EnableAuth = v
}
if token, ok := data["token"]; ok {
s.Config.Tokens = append(s.Config.Tokens, token)
}
// 保存配置文件
logger.Infof("Config: %+v", s.Config)
err = types.SaveConfig(s.Config, s.ConfigPath)