mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 19:23:42 +08:00
添加会话授权支持
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user