Refactor import paths to use internal/pkg/httpx/params
- 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.
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var AgentProfileService = newAgentProfileService()
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"cs-agent/internal/repositories"
|
||||
"strings"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var AgentRunLogService = newAgentRunLogService()
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var AgentTeamService = newAgentTeamService()
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var AIAgentService = newAIAgentService()
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var AIConfigService = newAIConfigService()
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -37,18 +37,18 @@ func newAuthService() *authService {
|
||||
type authService struct {
|
||||
}
|
||||
|
||||
func (s *authService) GetAuthPrincipal(ctx iris.Context) *dto.AuthPrincipal {
|
||||
func (s *authService) GetAuthPrincipal(ctx *gin.Context) *dto.AuthPrincipal {
|
||||
if ctx == nil {
|
||||
return nil
|
||||
}
|
||||
v := ctx.Values().Get(authPrincipalContextKey)
|
||||
v, _ := ctx.Get(authPrincipalContextKey)
|
||||
if principal, ok := v.(*dto.AuthPrincipal); ok {
|
||||
return principal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *authService) setAuthPrincipal(ctx iris.Context, user *models.User, roles, permissions []string) *dto.AuthPrincipal {
|
||||
func (s *authService) setAuthPrincipal(ctx *gin.Context, user *models.User, roles, permissions []string) *dto.AuthPrincipal {
|
||||
principal := &dto.AuthPrincipal{
|
||||
UserID: user.ID,
|
||||
Username: user.Username,
|
||||
@@ -58,11 +58,11 @@ func (s *authService) setAuthPrincipal(ctx iris.Context, user *models.User, role
|
||||
Roles: roles,
|
||||
Permissions: permissions,
|
||||
}
|
||||
ctx.Values().Set(authPrincipalContextKey, principal)
|
||||
ctx.Set(authPrincipalContextKey, principal)
|
||||
return principal
|
||||
}
|
||||
|
||||
func (s *authService) RequirePermission(ctx iris.Context, permission constants.Permission) (principal *dto.AuthPrincipal, err error) {
|
||||
func (s *authService) RequirePermission(ctx *gin.Context, permission constants.Permission) (principal *dto.AuthPrincipal, err error) {
|
||||
if principal = s.GetAuthPrincipal(ctx); principal == nil {
|
||||
if principal, err = s.Authenticate(ctx); err != nil {
|
||||
return nil, err
|
||||
@@ -143,14 +143,14 @@ func (s *authService) Logout(accessToken string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *authService) Authenticate(ctx iris.Context) (*dto.AuthPrincipal, error) {
|
||||
func (s *authService) Authenticate(ctx *gin.Context) (*dto.AuthPrincipal, error) {
|
||||
if principal := s.GetAuthPrincipal(ctx); principal != nil {
|
||||
return principal, nil
|
||||
}
|
||||
|
||||
token := s.extractBearerToken(ctx.GetHeader("Authorization"))
|
||||
if token == "" {
|
||||
token = strings.TrimSpace(ctx.URLParam("accessToken"))
|
||||
token = strings.TrimSpace(ctx.Query("accessToken"))
|
||||
}
|
||||
if token == "" {
|
||||
return nil, errorsx.Unauthorized("未登录或登录已过期")
|
||||
@@ -181,7 +181,7 @@ func (s *authService) Authenticate(ctx iris.Context) (*dto.AuthPrincipal, error)
|
||||
return principal, nil
|
||||
}
|
||||
|
||||
func (s *authService) HasPermission(ctx iris.Context, permissionCode string) bool {
|
||||
func (s *authService) HasPermission(ctx *gin.Context, permissionCode string) bool {
|
||||
principal := s.GetAuthPrincipal(ctx)
|
||||
if principal == nil {
|
||||
return false
|
||||
@@ -189,7 +189,7 @@ func (s *authService) HasPermission(ctx iris.Context, permissionCode string) boo
|
||||
return slices.Contains(principal.Permissions, permissionCode)
|
||||
}
|
||||
|
||||
func (s *authService) CurrentProfile(ctx iris.Context) (*response.LoginResponse, error) {
|
||||
func (s *authService) CurrentProfile(ctx *gin.Context) (*response.LoginResponse, error) {
|
||||
principal, err := s.Authenticate(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var ChannelMessageOutboxService = newChannelMessageOutboxService()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/pkg/errorsx"
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
"cs-agent/internal/wxwork"
|
||||
@@ -17,10 +17,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"github.com/silenceper/wechat/v2/work/kf"
|
||||
)
|
||||
|
||||
@@ -369,8 +369,8 @@ func (s *channelService) GetEnabledWxWorkKFChannelByOpenKfID(openKfID string) *m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *channelService) GetEnabledChannel(ctx iris.Context) *models.Channel {
|
||||
channelID := irisx.GetChannelID(ctx)
|
||||
func (s *channelService) GetEnabledChannel(ctx *gin.Context) *models.Channel {
|
||||
channelID := httpx.GetChannelID(ctx)
|
||||
channel := repositories.ChannelRepository.GetByChannelID(sqls.DB(), channelID)
|
||||
if channel == nil {
|
||||
return nil
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var CompanyService = newCompanyService()
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var ConversationAssignmentService = newConversationAssignmentService()
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var ConversationEventLogService = newConversationEventLogService()
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"cs-agent/internal/repositories"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var ConversationParticipantService = newConversationParticipantService()
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"cs-agent/internal/repositories"
|
||||
"errors"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var ConversationTagService = newConversationTagService()
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var CustomerIdentityService = newCustomerIdentityService()
|
||||
@@ -64,4 +64,3 @@ func (s *customerIdentityService) UpdateColumn(id int64, name string, value inte
|
||||
func (s *customerIdentityService) Delete(id int64) {
|
||||
repositories.CustomerIdentityRepository.Delete(sqls.DB(), id)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"cs-agent/internal/pkg/openidentity"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -115,7 +115,7 @@ func (s *customerSessionService) Sign(channel *models.Channel, customer *models.
|
||||
return token, expiresAt, nil
|
||||
}
|
||||
|
||||
func (s *customerSessionService) VerifyRequest(ctx iris.Context, channel *models.Channel) (*CustomerSessionVerifyResult, error) {
|
||||
func (s *customerSessionService) VerifyRequest(ctx *gin.Context, channel *models.Channel) (*CustomerSessionVerifyResult, error) {
|
||||
token := s.getCustomerSessionToken(ctx)
|
||||
if token == "" {
|
||||
return nil, errorsx.Unauthorized("客服会话不能为空")
|
||||
@@ -155,7 +155,7 @@ func (s *customerSessionService) VerifyRequest(ctx iris.Context, channel *models
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *customerSessionService) SetRefreshHeaders(ctx iris.Context, result *CustomerSessionVerifyResult) {
|
||||
func (s *customerSessionService) SetRefreshHeaders(ctx *gin.Context, result *CustomerSessionVerifyResult) {
|
||||
if ctx == nil || result == nil || !result.Refreshed {
|
||||
return
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (s *customerSessionService) identityKey(externalUser openidentity.ExternalU
|
||||
}
|
||||
}
|
||||
|
||||
func (s *customerSessionService) getCustomerSessionToken(ctx iris.Context) string {
|
||||
func (s *customerSessionService) getCustomerSessionToken(ctx *gin.Context) string {
|
||||
auth := strings.TrimSpace(ctx.GetHeader("Authorization"))
|
||||
if len(auth) > 7 && strings.EqualFold(auth[:7], "Bearer ") {
|
||||
if token := strings.TrimSpace(auth[7:]); token != "" {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var KnowledgeBaseService = newKnowledgeBaseService()
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var KnowledgeDocumentService = newKnowledgeDocumentService()
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var KnowledgeFAQService = newKnowledgeFAQService()
|
||||
|
||||
@@ -3,8 +3,8 @@ package services
|
||||
import (
|
||||
"cs-agent/internal/models"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var KnowledgeRetrieveLogService = newKnowledgeRetrieveLogService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var LoginCredentialLogService = newLoginCredentialLogService()
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"cs-agent/internal/repositories"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var LoginSessionService = newLoginSessionService()
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/common/strs"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var MessageService = newMessageService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var MigrationService = newMigrationService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var PermissionService = newPermissionService()
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var QuickReplyService = newQuickReplyService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var RolePermissionService = newRolePermissionService()
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var RoleService = newRoleService()
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var SkillDefinitionService = newSkillDefinitionService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var SkillRunLogService = newSkillRunLogService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var SystemConfigService = newSystemConfigService()
|
||||
@@ -64,4 +64,3 @@ func (s *systemConfigService) UpdateColumn(id int64, name string, value interfac
|
||||
func (s *systemConfigService) Delete(id int64) {
|
||||
repositories.SystemConfigRepository.Delete(sqls.DB(), id)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var TagService = newTagService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var TicketProgressService = newTicketProgressService()
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"cs-agent/internal/pkg/utils"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var UserIdentityService = newUserIdentityService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var UserPermissionService = newUserPermissionService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var UserRoleService = newUserRoleService()
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
@@ -41,36 +41,36 @@ func newWsService() *wsService {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *wsService) HandleDashboardWS(ctx iris.Context) {
|
||||
func (s *wsService) HandleDashboardWS(ctx *gin.Context) {
|
||||
principal := AuthService.GetAuthPrincipal(ctx)
|
||||
if principal == nil {
|
||||
_ = ctx.StopWithJSON(iris.StatusUnauthorized, web.JsonError(errorsx.Unauthorized("未登录或登录已过期")))
|
||||
ctx.AbortWithStatusJSON(http.StatusUnauthorized, web.JsonError(errorsx.Unauthorized("未登录或登录已过期")))
|
||||
return
|
||||
}
|
||||
if err := s.upgradeConnection(ctx, principal, nil, realtimeRoleAdmin); err != nil {
|
||||
slog.Error("upgrade admin websocket failed", "error", err, "path", ctx.Path())
|
||||
ctx.StopExecution()
|
||||
slog.Error("upgrade admin websocket failed", "error", err, "path", ctx.Request.URL.Path)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *wsService) HandleDashboardNotificationWS(ctx iris.Context) {
|
||||
func (s *wsService) HandleDashboardNotificationWS(ctx *gin.Context) {
|
||||
principal := AuthService.GetAuthPrincipal(ctx)
|
||||
if principal == nil {
|
||||
_ = ctx.StopWithJSON(iris.StatusUnauthorized, web.JsonError(errorsx.Unauthorized("未登录或登录已过期")))
|
||||
ctx.AbortWithStatusJSON(http.StatusUnauthorized, web.JsonError(errorsx.Unauthorized("未登录或登录已过期")))
|
||||
return
|
||||
}
|
||||
if err := s.upgradeConnection(ctx, principal, nil, realtimeRoleNotification); err != nil {
|
||||
slog.Error("upgrade dashboard notification websocket failed", "error", err, "path", ctx.Path())
|
||||
ctx.StopExecution()
|
||||
slog.Error("upgrade dashboard notification websocket failed", "error", err, "path", ctx.Request.URL.Path)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *wsService) HandleOpenWS(ctx iris.Context) {
|
||||
func (s *wsService) HandleOpenWS(ctx *gin.Context) {
|
||||
channel := ChannelService.GetEnabledChannel(ctx)
|
||||
if channel == nil {
|
||||
_ = ctx.StopWithJSON(iris.StatusBadRequest, web.JsonErrorMsg("接入渠道不存在或已停用"))
|
||||
ctx.AbortWithStatusJSON(http.StatusBadRequest, web.JsonErrorMsg("接入渠道不存在或已停用"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,21 +82,21 @@ func (s *wsService) HandleOpenWS(ctx iris.Context) {
|
||||
if principal == nil {
|
||||
result, err := CustomerSessionService.VerifyRequest(ctx, channel)
|
||||
if err != nil {
|
||||
_ = ctx.StopWithJSON(iris.StatusUnauthorized, web.JsonError(err))
|
||||
ctx.AbortWithStatusJSON(http.StatusUnauthorized, web.JsonError(err))
|
||||
return
|
||||
}
|
||||
external = result.ExternalUser
|
||||
customerSessionInfo = result
|
||||
}
|
||||
if err := s.upgradeConnection(ctx, principal, external, realtimeRoleUser, customerSessionInfo); err != nil {
|
||||
slog.Error("upgrade open im websocket failed", "error", err, "path", ctx.Path(), "channelId", channel.ChannelID, "channel_id", channel.ID)
|
||||
ctx.StopExecution()
|
||||
slog.Error("upgrade open im websocket failed", "error", err, "path", ctx.Request.URL.Path, "channelId", channel.ChannelID, "channel_id", channel.ID)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *wsService) upgradeConnection(ctx iris.Context, principal *dto.AuthPrincipal, external *openidentity.ExternalUser, role string, customerSessionInfo ...*CustomerSessionVerifyResult) error {
|
||||
conn, err := s.upgrader.Upgrade(ctx.ResponseWriter().Naive(), ctx.Request(), nil)
|
||||
func (s *wsService) upgradeConnection(ctx *gin.Context, principal *dto.AuthPrincipal, external *openidentity.ExternalUser, role string, customerSessionInfo ...*CustomerSessionVerifyResult) error {
|
||||
conn, err := s.upgrader.Upgrade(ctx.Writer, ctx.Request, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -643,11 +643,11 @@ func (s *wsService) canSubscribeConversation(session *ClientSession, conversatio
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *wsService) resolveTerminalType(ctx iris.Context, role string) string {
|
||||
func (s *wsService) resolveTerminalType(ctx *gin.Context, role string) string {
|
||||
if ctx == nil {
|
||||
return "web"
|
||||
}
|
||||
terminalType := strings.TrimSpace(ctx.URLParam("terminalType"))
|
||||
terminalType := strings.TrimSpace(ctx.Query("terminalType"))
|
||||
if terminalType != "" {
|
||||
return terminalType
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var WxWorkKFConversationService = newWxWorkKFConversationService()
|
||||
@@ -64,4 +64,3 @@ func (s *wxWorkKFConversationService) UpdateColumn(id int64, name string, value
|
||||
func (s *wxWorkKFConversationService) Delete(id int64) {
|
||||
repositories.WxWorkKFConversationRepository.Delete(sqls.DB(), id)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var WxWorkKFMessageRefService = newWxWorkKFMessageRefService()
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/repositories"
|
||||
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
var WxWorkKFSyncStateService = newWxWorkKFSyncStateService()
|
||||
|
||||
Reference in New Issue
Block a user