Refactor API routes and controllers for improved structure and clarity
- 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.
This commit is contained in:
@@ -3,38 +3,13 @@ package middleware
|
||||
import (
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/pkg/openidentity"
|
||||
"cs-agent/internal/services"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
// OpenImContextMiddleware 校验 X-Channel-Id / channelId 对应启用 web 渠道;除 /api/open/im/widget 外解析并缓存外部访客身份。
|
||||
func OpenImContextMiddleware(ctx iris.Context) {
|
||||
channelID := strings.TrimSpace(ctx.GetHeader("X-Channel-Id"))
|
||||
if channelID == "" {
|
||||
channelID = strings.TrimSpace(ctx.URLParam("channelId"))
|
||||
}
|
||||
if channelID == "" {
|
||||
ctx.StopExecution()
|
||||
_ = ctx.JSON(web.JsonErrorMsg("channelId不能为空"))
|
||||
return
|
||||
}
|
||||
channel := services.ChannelService.GetEnabledWebChannelByChannelID(channelID)
|
||||
if channel == nil {
|
||||
ctx.StopExecution()
|
||||
_ = ctx.JSON(web.JsonErrorMsg("接入渠道不存在或已停用"))
|
||||
return
|
||||
}
|
||||
irisx.SetOpenImChannel(ctx, channel)
|
||||
|
||||
path := ctx.Path()
|
||||
if strings.Contains(path, "/open/im/widget") {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// ChannelContextMiddleware 校验 X-Channel-Id / channelId 对应启用 web 渠道
|
||||
func ChannelContextMiddleware(ctx iris.Context) {
|
||||
ext, err := openidentity.GetExternalInfo(ctx)
|
||||
if err != nil {
|
||||
ctx.StopExecution()
|
||||
|
||||
Reference in New Issue
Block a user