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:
@@ -3,17 +3,18 @@ package api
|
||||
import (
|
||||
"cs-agent/internal/pkg/config"
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"cs-agent/internal/services"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
type AuthController struct {
|
||||
Ctx iris.Context
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func (c *AuthController) PostLogin() *web.JsonResult {
|
||||
@@ -23,7 +24,7 @@ func (c *AuthController) PostLogin() *web.JsonResult {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
|
||||
ret, err := services.AuthService.Login(req, cfg.Auth, c.Ctx.RemoteAddr(), c.Ctx.GetHeader("User-Agent"))
|
||||
ret, err := services.AuthService.Login(req, cfg.Auth, c.Ctx.ClientIP(), c.Ctx.GetHeader("User-Agent"))
|
||||
if err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
@@ -31,37 +32,37 @@ func (c *AuthController) PostLogin() *web.JsonResult {
|
||||
}
|
||||
|
||||
func (c *AuthController) GetWxwork_login() {
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkLoginURL(c.Ctx.URLParam("next"))
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkLoginURL(c.Ctx.Query("next"))
|
||||
if err != nil {
|
||||
c.redirectWxWorkError(err.Error())
|
||||
return
|
||||
}
|
||||
c.Ctx.Redirect(loginURL, iris.StatusFound)
|
||||
c.Ctx.Redirect(http.StatusFound, loginURL)
|
||||
}
|
||||
|
||||
func (c *AuthController) GetWxwork_qr_login() {
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkQRCodeLoginURL(c.Ctx.URLParam("next"))
|
||||
loginURL, err := services.WxWorkLoginService.BuildWxWorkQRCodeLoginURL(c.Ctx.Query("next"))
|
||||
if err != nil {
|
||||
c.redirectWxWorkError(err.Error())
|
||||
return
|
||||
}
|
||||
c.Ctx.Redirect(loginURL, iris.StatusFound)
|
||||
c.Ctx.Redirect(http.StatusFound, loginURL)
|
||||
}
|
||||
|
||||
func (c *AuthController) GetWxwork_callback() {
|
||||
cfg := config.Current()
|
||||
ticket, next, err := services.WxWorkLoginService.LoginByWxWork(
|
||||
c.Ctx.URLParam("code"),
|
||||
c.Ctx.URLParam("state"),
|
||||
c.Ctx.Query("code"),
|
||||
c.Ctx.Query("state"),
|
||||
cfg.Auth,
|
||||
c.Ctx.RemoteAddr(),
|
||||
c.Ctx.ClientIP(),
|
||||
c.Ctx.GetHeader("User-Agent"),
|
||||
)
|
||||
if err != nil {
|
||||
c.redirectWxWorkError(err.Error())
|
||||
return
|
||||
}
|
||||
c.Ctx.Redirect("/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next), iris.StatusFound)
|
||||
c.Ctx.Redirect(http.StatusFound, "/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next))
|
||||
}
|
||||
|
||||
func (c *AuthController) PostWxwork_exchange() *web.JsonResult {
|
||||
@@ -95,5 +96,5 @@ func (c *AuthController) redirectWxWorkError(message string) {
|
||||
if idx := strings.Index(message, ": "); idx >= 0 {
|
||||
message = message[idx+2:]
|
||||
}
|
||||
c.Ctx.Redirect("/login?wxworkError="+url.QueryEscape(message), iris.StatusFound)
|
||||
c.Ctx.Redirect(http.StatusFound, "/login?wxworkError="+url.QueryEscape(message))
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"cs-agent/internal/pkg/errorsx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
type ChannelController struct {
|
||||
Ctx iris.Context
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func (c *ChannelController) AnyConfig() *web.JsonResult {
|
||||
|
||||
@@ -4,23 +4,23 @@ import (
|
||||
"cs-agent/internal/builders"
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/dto/response"
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
)
|
||||
|
||||
type ConversationController struct {
|
||||
Ctx iris.Context
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func (c *ConversationController) GetBy(id int64) *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (c *ConversationController) PostCreate_or_match() *web.JsonResult {
|
||||
if channel == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (c *ConversationController) PostClose() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"cs-agent/internal/pkg/openidentity"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
)
|
||||
|
||||
type CustomerController struct {
|
||||
Ctx iris.Context
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func (c *CustomerController) PostSession_exchange() *web.JsonResult {
|
||||
|
||||
@@ -4,26 +4,26 @@ import (
|
||||
"cs-agent/internal/builders"
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/pkg/irisx"
|
||||
"cs-agent/internal/pkg/httpx"
|
||||
"cs-agent/internal/services"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"cs-agent/internal/pkg/httpx/params"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mlogclub/simple/web"
|
||||
"github.com/mlogclub/simple/web/params"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type MessageController struct {
|
||||
Ctx iris.Context
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func (c *MessageController) AnyList() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (c *MessageController) PostSend() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (c *MessageController) PostRead() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
@@ -97,12 +97,12 @@ func (c *MessageController) PostUpload_image() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
|
||||
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
|
||||
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
|
||||
if rawConv == "" {
|
||||
return web.JsonErrorMsg("conversationId不能为空")
|
||||
}
|
||||
@@ -121,12 +121,10 @@ func (c *MessageController) PostUpload_image() *web.JsonResult {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
|
||||
f, header, err := c.Ctx.FormFile("file")
|
||||
header, err := c.Ctx.FormFile("file")
|
||||
if err != nil {
|
||||
return web.JsonErrorMsg("请选择上传图片")
|
||||
}
|
||||
_ = f.Close()
|
||||
|
||||
if !strings.HasPrefix(strings.ToLower(header.Header.Get("Content-Type")), "image/") {
|
||||
return web.JsonErrorMsg("仅支持上传图片文件")
|
||||
}
|
||||
@@ -142,12 +140,12 @@ func (c *MessageController) PostUpload_attachment() *web.JsonResult {
|
||||
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
||||
return web.JsonErrorMsg("接入渠道未初始化")
|
||||
}
|
||||
external := irisx.GetExternalUser(c.Ctx)
|
||||
external := httpx.GetExternalUser(c.Ctx)
|
||||
if external == nil {
|
||||
return web.JsonErrorMsg("外部身份未初始化")
|
||||
}
|
||||
|
||||
rawConv := strings.TrimSpace(c.Ctx.FormValue("conversationId"))
|
||||
rawConv := strings.TrimSpace(params.FormValue(c.Ctx, "conversationId"))
|
||||
if rawConv == "" {
|
||||
return web.JsonErrorMsg("conversationId不能为空")
|
||||
}
|
||||
@@ -159,12 +157,10 @@ func (c *MessageController) PostUpload_attachment() *web.JsonResult {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
|
||||
f, header, err := c.Ctx.FormFile("file")
|
||||
header, err := c.Ctx.FormFile("file")
|
||||
if err != nil {
|
||||
return web.JsonErrorMsg("请选择上传附件")
|
||||
}
|
||||
_ = f.Close()
|
||||
|
||||
item, err := services.AssetService.UploadFile(header, "attachments", nil)
|
||||
if err != nil {
|
||||
return web.JsonError(err)
|
||||
|
||||
Reference in New Issue
Block a user