fix
This commit is contained in:
parent
8e4e1c1cfd
commit
36efad44df
|
@ -5,9 +5,9 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/id_generator"
|
"fusenapi/utils/id_generator"
|
||||||
|
"fusenapi/utils/websocket_data"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -251,7 +251,7 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
|
||||||
|
|
||||||
// 格式化返回数据
|
// 格式化返回数据
|
||||||
func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte {
|
func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte {
|
||||||
d := types.DataTransferData{
|
d := websocket_data.DataTransferData{
|
||||||
T: msgType,
|
T: msgType,
|
||||||
D: data,
|
D: data,
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by
|
||||||
|
|
||||||
// 处理接受到的数据
|
// 处理接受到的数据
|
||||||
func (w *wsConnectItem) dealwithReciveData(data []byte) {
|
func (w *wsConnectItem) dealwithReciveData(data []byte) {
|
||||||
var parseInfo types.DataTransferData
|
var parseInfo websocket_data.DataTransferData
|
||||||
if err := json.Unmarshal(data, &parseInfo); err != nil {
|
if err := json.Unmarshal(data, &parseInfo); err != nil {
|
||||||
logx.Error("invalid format of websocket message")
|
logx.Error("invalid format of websocket message")
|
||||||
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data))
|
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package logic
|
||||||
import (
|
import (
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/websocket_data"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -66,7 +67,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, types.RenderImageRspMsg{
|
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||||
RenderId: renderId,
|
RenderId: renderId,
|
||||||
Image: req.Info.Image,
|
Image: req.Info.Image,
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/websocket_data"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -66,7 +67,7 @@ func (l *ThirdPartyLoginNotifyLogic) ThirdPartyLoginNotify(req *types.ThirdParty
|
||||||
if !ok {
|
if !ok {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "type of websocket connect object is err")
|
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,
|
Token: req.Info.Token,
|
||||||
})
|
})
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -3,8 +3,8 @@ package logic
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/server/websocket/internal/types"
|
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
|
"fusenapi/utils/websocket_data"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ type assembleRenderData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wsConnectItem) assembleRenderData(data []byte) {
|
func (w *wsConnectItem) assembleRenderData(data []byte) {
|
||||||
var renderImageData types.RenderImageReqMsg
|
var renderImageData websocket_data.RenderImageReqMsg
|
||||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
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))
|
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)
|
logx.Error("invalid format of websocket render image message", err)
|
||||||
|
|
|
@ -5,25 +5,6 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"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 {
|
type RenderNotifyReq struct {
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
Time int64 `json:"time"`
|
Time int64 `json:"time"`
|
||||||
|
|
|
@ -20,22 +20,6 @@ service websocket {
|
||||||
post /api/websocket/third_party_login_notify(ThirdPartyLoginNotifyReq) returns (response);
|
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 {
|
type RenderNotifyReq {
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
|
|
21
utils/websocket_data/render_data.go
Normal file
21
utils/websocket_data/render_data.go
Normal file
|
@ -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"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user