Files
ai-agent/internal/handlers/api/channel_handler.go
T
t 2bbf42b741 refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
2026-08-21 00:41:07 +08:00

75 lines
1.8 KiB
Go

package api
import (
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/response"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/errorsx"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx"
"code.tczkiot.com/wlw/ai-agent/internal/services"
"github.com/gin-gonic/gin"
)
func ChannelAnyConfig(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
if channel == nil {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
ret := response.WidgetConfigResponse{
ChannelID: channel.ChannelID,
ChannelType: channel.ChannelType,
Title: cfg.Title,
Subtitle: cfg.Subtitle,
ThemeColor: cfg.ThemeColor,
Position: cfg.Position,
Width: cfg.Width,
}
httpx.WriteJSON(ctx, 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.InvalidParamI18n("error.e0313")
}
}