add API for get and set image url for wechat

This commit is contained in:
RockYang
2023-04-27 10:45:19 +08:00
parent d2201596f6
commit 6409531ee4
5 changed files with 45 additions and 0 deletions

View File

@@ -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})
}

View File

@@ -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)