96168dc6fb
- Updated API route structure to remove versioning and consolidate endpoints. - Refactored routing in `server.go` to use a unified `/api` prefix for all controllers. - Added new `ChannelController`, `ConversationController`, and `MessageController` to handle specific API functionalities. - Removed deprecated `OpenImContextMiddleware` and related logic. - Enhanced channel validation logic in `ChannelService` and `ChannelRepository`. - Updated frontend API calls to align with new endpoint structure.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package irisx
|
|
|
|
import (
|
|
"cs-agent/internal/pkg/openidentity"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
"github.com/mlogclub/simple/common/strs"
|
|
"github.com/mlogclub/simple/web/params"
|
|
)
|
|
|
|
const (
|
|
ctxKeyOpenImChannel = "openImChannel"
|
|
ctxKeyOpenImExternalInfo = "openImExternalInfo"
|
|
)
|
|
|
|
// func SetOpenImChannel(ctx iris.Context, channel *models.Channel) {
|
|
// ctx.Values().Set(ctxKeyOpenImChannel, channel)
|
|
// }
|
|
|
|
// // GetChannel 返回 OpenImContextMiddleware 注入的接入渠道(未走中间件时为 nil)。
|
|
// func GetChannel(ctx iris.Context) *models.Channel {
|
|
// v := ctx.Values().Get(ctxKeyOpenImChannel)
|
|
// channel, _ := v.(*models.Channel)
|
|
// return channel
|
|
// }
|
|
|
|
func SetOpenImExternalInfo(ctx iris.Context, ext *openidentity.ExternalInfo) {
|
|
ctx.Values().Set(ctxKeyOpenImExternalInfo, ext)
|
|
}
|
|
|
|
// GetExternalInfo 返回中间件注入的外部访客身份;仅 widget 子路径或未启用中间件时为 nil。
|
|
func GetExternalInfo(ctx iris.Context) *openidentity.ExternalInfo {
|
|
v := ctx.Values().Get(ctxKeyOpenImExternalInfo)
|
|
ext, _ := v.(*openidentity.ExternalInfo)
|
|
return ext
|
|
}
|
|
|
|
func GetChannelID(ctx iris.Context) string {
|
|
if channelID := ctx.GetHeader("X-Channel-ID"); strs.IsNotBlank(channelID) {
|
|
return channelID
|
|
}
|
|
if channelID, _ := params.Get(ctx, "channelId"); strs.IsNotBlank(channelID) {
|
|
return channelID
|
|
}
|
|
return ""
|
|
}
|