mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
add API for get and set image url for wechat
This commit is contained in:
parent
d2201596f6
commit
6409531ee4
@ -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})
|
||||
}
|
@ -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)
|
||||
|
@ -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"` // 微信群二维码
|
||||
}
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user