diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 1865300d..ab215c78 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fusenapi/constants" "fusenapi/initalize" - "fusenapi/server/websocket/internal/types" "fusenapi/utils/auth" "fusenapi/utils/id_generator" + "fusenapi/utils/websocket_data" "github.com/gorilla/websocket" "net/http" "sync" @@ -251,7 +251,7 @@ func (w *wsConnectItem) sendToOutChan(data []byte) { // 格式化返回数据 func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte { - d := types.DataTransferData{ + d := websocket_data.DataTransferData{ T: msgType, D: data, } @@ -261,7 +261,7 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by // 处理接受到的数据 func (w *wsConnectItem) dealwithReciveData(data []byte) { - var parseInfo types.DataTransferData + var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { logx.Error("invalid format of websocket message") w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data)) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index f499157f..27b2002d 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -3,6 +3,7 @@ package logic import ( "fusenapi/constants" "fusenapi/utils/basic" + "fusenapi/utils/websocket_data" "time" "context" @@ -66,7 +67,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi if !ok { return true } - b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, types.RenderImageRspMsg{ + b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: renderId, Image: req.Info.Image, }) diff --git a/server/websocket/internal/logic/thirdpartyloginnotifylogic.go b/server/websocket/internal/logic/thirdpartyloginnotifylogic.go index d363ffd9..d3639a95 100644 --- a/server/websocket/internal/logic/thirdpartyloginnotifylogic.go +++ b/server/websocket/internal/logic/thirdpartyloginnotifylogic.go @@ -4,6 +4,7 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/websocket_data" "time" "context" @@ -66,7 +67,7 @@ func (l *ThirdPartyLoginNotifyLogic) ThirdPartyLoginNotify(req *types.ThirdParty if !ok { return resp.SetStatusWithMessage(basic.CodeServiceErr, "type of websocket connect object is err") } - b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, types.ThirdPartyLoginRspMsg{ + b := ws.respondDataFormat(constants.WEBSOCKET_THIRD_PARTY_LOGIN_NOTIFY, websocket_data.ThirdPartyLoginRspMsg{ Token: req.Info.Token, }) select { diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index ca93a6c7..5be69551 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -3,8 +3,8 @@ package logic import ( "encoding/json" "fusenapi/constants" - "fusenapi/server/websocket/internal/types" "fusenapi/utils/hash" + "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" ) @@ -28,7 +28,7 @@ type assembleRenderData struct { } func (w *wsConnectItem) assembleRenderData(data []byte) { - var renderImageData types.RenderImageReqMsg + var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data)) logx.Error("invalid format of websocket render image message", err) diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 141d7e5e..67d38865 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -5,25 +5,6 @@ import ( "fusenapi/utils/basic" ) -type DataTransferData struct { - T string `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 -} - -type RenderImageReqMsg struct { - RenderId string `json:"render_id"` //渲染id - RenderData interface{} `json:"render_data"` //参数数据 -} - -type RenderImageRspMsg struct { - RenderId string `json:"render_id"` //渲染id - Image string `json:"image"` //渲染结果图片 -} - -type ThirdPartyLoginRspMsg struct { - Token string `json:"token"` -} - type RenderNotifyReq struct { Sign string `json:"sign"` Time int64 `json:"time"` diff --git a/server_api/websocket.api b/server_api/websocket.api index 254e29a5..22104825 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -20,22 +20,6 @@ service websocket { post /api/websocket/third_party_login_notify(ThirdPartyLoginNotifyReq) returns (response); } -//websocket数据交互 -type DataTransferData { - T string `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 -} -type RenderImageReqMsg { //websocket接受要云渲染处理的数据 - RenderId string `json:"render_id"` //渲染id - RenderData interface{} `json:"render_data"` //参数数据 -} -type RenderImageRspMsg { //websocket发送渲染完的数据 - RenderId string `json:"render_id"` //渲染id - Image string `json:"image"` //渲染结果图片 -} -type ThirdPartyLoginRspMsg { //websocket三方登录的通知数据 - Token string `json:"token"` -} //渲染完了通知接口 type RenderNotifyReq { Sign string `json:"sign"` diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go new file mode 100644 index 00000000..2e6c6a9e --- /dev/null +++ b/utils/websocket_data/render_data.go @@ -0,0 +1,21 @@ +package websocket_data + +// websocket数据交互 +type DataTransferData struct { + T string `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 +} +type RenderImageReqMsg struct { + //websocket接受要云渲染处理的数据 + RenderId string `json:"render_id"` //渲染id + RenderData interface{} `json:"render_data"` //参数数据 +} +type RenderImageRspMsg struct { + //websocket发送渲染完的数据 + RenderId string `json:"render_id"` //渲染id + Image string `json:"image"` //渲染结果图片 +} +type ThirdPartyLoginRspMsg struct { + //websocket三方登录的通知数据 + Token string `json:"token"` +}