fix
This commit is contained in:
parent
736f57c0c2
commit
e40a4d43f4
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/server/websocket/internal/types"
|
"fusenapi/server/websocket/internal/types"
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -56,7 +55,7 @@ type wsConnectItem struct {
|
||||||
renderImage map[string]struct{} //需要渲染的图片
|
renderImage map[string]struct{} //需要渲染的图片
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) (resp *basic.Response) {
|
func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) {
|
||||||
//升级websocket
|
//升级websocket
|
||||||
conn, err := upgrade.Upgrade(w, r, nil)
|
conn, err := upgrade.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -130,8 +129,6 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
||||||
go ws.sendLoop()
|
go ws.sendLoop()
|
||||||
//心跳
|
//心跳
|
||||||
ws.heartbeat()
|
ws.heartbeat()
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 心跳
|
// 心跳
|
||||||
|
@ -225,23 +222,11 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
|
||||||
logx.Error("invalid format of websocket message")
|
logx.Error("invalid format of websocket message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//分消息类型给到不同逻辑处理,可扩展
|
||||||
switch parseInfo.T {
|
switch parseInfo.T {
|
||||||
//图片渲染
|
//图片渲染
|
||||||
case constants.WEBSOCKET_RENDER_IMAGE:
|
case constants.WEBSOCKET_RENDER_IMAGE:
|
||||||
var renderImageData []types.RenderImageReqMsg
|
w.SendToCloudRender([]byte(parseInfo.D))
|
||||||
if err := json.Unmarshal([]byte(parseInfo.D), &renderImageData); err != nil {
|
|
||||||
logx.Error("invalid format of websocket render image message", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logx.Info("收到请求云渲染图片数据:", renderImageData)
|
|
||||||
w.mutex.Lock()
|
|
||||||
defer w.mutex.Unlock()
|
|
||||||
//把需要渲染的图片加进去
|
|
||||||
for _, v := range renderImageData {
|
|
||||||
key := w.getRenderImageMapKey(v.ProductId, v.SizeId, v.TemplateId)
|
|
||||||
w.renderImage[key] = struct{}{}
|
|
||||||
}
|
|
||||||
//TODO 发送数据到云渲染服务器
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
24
server/websocket/internal/logic/ws_render_image_logic.go
Normal file
24
server/websocket/internal/logic/ws_render_image_logic.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fusenapi/server/websocket/internal/types"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 渲染请求数据处理发送云渲染服务处理
|
||||||
|
func (w *wsConnectItem) SendToCloudRender(data []byte) {
|
||||||
|
var renderImageData []types.RenderImageReqMsg
|
||||||
|
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||||
|
logx.Error("invalid format of websocket render image message", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logx.Info("收到请求云渲染图片数据:", renderImageData)
|
||||||
|
w.mutex.Lock()
|
||||||
|
defer w.mutex.Unlock()
|
||||||
|
//把需要渲染的图片加进去
|
||||||
|
for _, v := range renderImageData {
|
||||||
|
key := w.getRenderImageMapKey(v.ProductId, v.SizeId, v.TemplateId)
|
||||||
|
w.renderImage[key] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user