79614b2d07
- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params". - Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context. - Ensured consistent usage of HTTP status responses across websocket handlers.
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"cs-agent/internal/pkg/dto/response"
|
|
"cs-agent/internal/pkg/enums"
|
|
"cs-agent/internal/pkg/errorsx"
|
|
"cs-agent/internal/services"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mlogclub/simple/web"
|
|
)
|
|
|
|
type ChannelController struct {
|
|
Ctx *gin.Context
|
|
}
|
|
|
|
func (c *ChannelController) AnyConfig() *web.JsonResult {
|
|
channel := services.ChannelService.GetEnabledChannel(c.Ctx)
|
|
if channel == nil {
|
|
return web.JsonErrorMsg("接入渠道未初始化")
|
|
}
|
|
cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON)
|
|
if err != nil {
|
|
return web.JsonError(err)
|
|
}
|
|
|
|
ret := response.WidgetConfigResponse{
|
|
ChannelID: channel.ChannelID,
|
|
ChannelType: channel.ChannelType,
|
|
Title: cfg.Title,
|
|
Subtitle: cfg.Subtitle,
|
|
ThemeColor: cfg.ThemeColor,
|
|
Position: cfg.Position,
|
|
Width: cfg.Width,
|
|
}
|
|
return web.JsonData(ret)
|
|
}
|
|
|
|
type webLikeWidgetConfig struct {
|
|
Title string
|
|
Subtitle string
|
|
ThemeColor string
|
|
Position string
|
|
Width string
|
|
}
|
|
|
|
func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, error) {
|
|
switch channelType {
|
|
case enums.ChannelTypeWeb:
|
|
cfg, err := services.ChannelService.ParseWebChannelConfig(rawConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &webLikeWidgetConfig{
|
|
Title: cfg.Title,
|
|
Subtitle: cfg.Subtitle,
|
|
ThemeColor: cfg.ThemeColor,
|
|
Position: cfg.Position,
|
|
Width: cfg.Width,
|
|
}, nil
|
|
case enums.ChannelTypeWechatMP:
|
|
cfg, err := services.ChannelService.ParseWechatMPChannelConfig(rawConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &webLikeWidgetConfig{
|
|
Title: cfg.Title,
|
|
Subtitle: cfg.Subtitle,
|
|
ThemeColor: cfg.ThemeColor,
|
|
Position: "right",
|
|
Width: "100%",
|
|
}, nil
|
|
default:
|
|
return nil, errorsx.InvalidParam("该渠道不支持开放客服配置")
|
|
}
|
|
}
|