Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-08-23 18:38:57 +08:00
commit 6d707fa9df
5 changed files with 12 additions and 4 deletions

View File

@ -93,7 +93,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
logx.Error("http upgrade websocket err:", err) logx.Error("http upgrade websocket err:", err)
return return
} }
defer conn.Close()
//鉴权不成功后断开 //鉴权不成功后断开
var ( var (
userInfo *auth.UserInfo userInfo *auth.UserInfo
@ -103,11 +102,13 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
if !isAuth { if !isAuth {
//未授权响应消息 //未授权响应消息
l.unAuthResponse(conn) l.unAuthResponse(conn)
conn.Close()
return return
} }
//设置连接 //设置连接
ws, err := l.setConnPool(conn, *userInfo) ws, err := l.setConnPool(conn, *userInfo)
if err != nil { if err != nil {
conn.Close()
return return
} }
defer ws.close() defer ws.close()
@ -249,7 +250,6 @@ func (w *wsConnectItem) heartbeat() {
//发送心跳信息 //发送心跳信息
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil { if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err) logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)
w.close()
return return
} }
} }

View File

@ -46,11 +46,13 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth
logx.Error("解密失败:", err) logx.Error("解密失败:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ")
} }
//真正的数据结构
var parseInfo websocket_data.NotifyData var parseInfo websocket_data.NotifyData
if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { if err = json.Unmarshal([]byte(data), &parseInfo); err != nil {
logx.Error("failed to parse json data:", err) logx.Error("failed to parse json data:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data")
} }
//websocket连接id不能为空
if parseInfo.WebsocketConnectId == "" { if parseInfo.WebsocketConnectId == "" {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty")
} }
@ -59,10 +61,12 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth
if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range")
} }
//查询websocket连接
value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId)
if !ok { if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
} }
//断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
logx.Error("渲染回调断言websocket连接失败") logx.Error("渲染回调断言websocket连接失败")

View File

@ -46,11 +46,13 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc
logx.Error("解密失败:", err) logx.Error("解密失败:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ")
} }
//真正的数据结构
var parseInfo websocket_data.NotifyData var parseInfo websocket_data.NotifyData
if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { if err = json.Unmarshal([]byte(data), &parseInfo); err != nil {
logx.Error("failed to parse json data:", err) logx.Error("failed to parse json data:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data")
} }
//websocket连接id不能为空
if parseInfo.WebsocketConnectId == "" { if parseInfo.WebsocketConnectId == "" {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty")
} }
@ -59,10 +61,12 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc
if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range")
} }
//查询websocket连接
value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId)
if !ok { if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
} }
//断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
logx.Error("渲染回调断言websocket连接失败") logx.Error("渲染回调断言websocket连接失败")

View File

@ -88,7 +88,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
}) })
//发送处理并删除任务 //发送处理并删除任务
ws.deleteRenderTask(renderImageControlChanItem{ ws.deleteRenderTask(renderImageControlChanItem{
Option: 0, //0删除 1添加 Option: 0, //0删除 1添加 2修改耗时属性
TaskId: req.TaskId, TaskId: req.TaskId,
RenderNotifyImageUrl: uploadRes.ResourceUrl, RenderNotifyImageUrl: uploadRes.ResourceUrl,
}) })

View File

@ -154,7 +154,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
//########################################### //###########################################
//把需要渲染的图片任务加进去 //把需要渲染的图片任务加进去
w.createRenderTask(renderImageControlChanItem{ w.createRenderTask(renderImageControlChanItem{
Option: 1, //0删除 1添加 Option: 1, //0删除 1添加 2修改耗时属性
TaskId: taskId, TaskId: taskId,
RenderId: renderImageData.RenderId, RenderId: renderImageData.RenderId,
}) })