diff --git a/server/chat_handler.go b/server/handler_chat.go similarity index 100% rename from server/chat_handler.go rename to server/handler_chat.go diff --git a/server/config_handler.go b/server/handler_config.go similarity index 93% rename from server/config_handler.go rename to server/handler_config.go index 12545f50..e90fb657 100644 --- a/server/config_handler.go +++ b/server/handler_config.go @@ -550,3 +550,39 @@ func (s *Server) RemoveProxyHandle(c *gin.Context) { c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: s.Config.ProxyURL}) } + +// SetImgURLHandle SetImgURL 设置图片地址集合 +func (s *Server) SetImgURLHandle(c *gin.Context) { + var data struct { + WechatCard string `json:"wechat_card"` // 个人微信二维码 + WechatGroup string `json:"wechat_group"` // 微信群聊二维码 + } + err := json.NewDecoder(c.Request.Body).Decode(&data) + if err != nil { + logger.Errorf("Error decode json data: %s", err.Error()) + c.JSON(http.StatusBadRequest, nil) + return + } + + if data.WechatCard != "" { + s.Config.ImgURL.WechatCard = data.WechatCard + } + if data.WechatGroup != "" { + s.Config.ImgURL.WechatGroup = data.WechatGroup + } + + // 保存配置文件 + err = utils.SaveConfig(s.Config, s.ConfigPath) + if err != nil { + c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: "Failed to save config file"}) + return + } + + c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: s.Config.ImgURL}) + +} + +// GetImgURLHandle 获取图片地址集合 +func (s *Server) GetImgURLHandle(c *gin.Context) { + c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: s.Config.ImgURL}) +} diff --git a/server/server.go b/server/server.go index 84bdc947..1134876e 100644 --- a/server/server.go +++ b/server/server.go @@ -95,6 +95,8 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) { engine.POST("api/chat/history", s.GetChatHistoryHandle) engine.POST("api/chat/history/clear", s.ClearHistoryHandle) engine.GET("api/role/hello", s.GetHelloMsgHandle) + engine.POST("api/img/get", s.GetImgURLHandle) + engine.POST("api/img/set", s.SetImgURLHandle) engine.POST("api/config/set", s.ConfigSetHandle) engine.GET("api/config/chat-roles/get", s.GetChatRoleListHandle) diff --git a/types/config.go b/types/config.go index 3012340f..0346deb1 100644 --- a/types/config.go +++ b/types/config.go @@ -11,6 +11,7 @@ type Config struct { EnableAuth bool // 是否开启鉴权 AccessKey string // 管理员访问 AccessKey, 通过传入这个参数可以访问系统管理 API Chat Chat + ImgURL ImgURL // 各种图片资源链接地址,比如微信二维码,群二维码 } type User struct { @@ -48,3 +49,8 @@ type Session struct { HttpOnly bool SameSite http.SameSite } + +type ImgURL struct { + WechatCard string `json:"wechat_card"` // 个人微信二维码 + WechatGroup string `json:"wechat_group"` // 微信群二维码 +} diff --git a/utils/config.go b/utils/config.go index 9a00401a..7747ba96 100644 --- a/utils/config.go +++ b/utils/config.go @@ -15,6 +15,7 @@ func NewDefaultConfig() *types.Config { ProxyURL: make([]string, 0), EnableAuth: true, AccessKey: "yangjian102621@gmail.com", + ImgURL: types.ImgURL{}, Session: types.Session{ SecretKey: RandString(64),