From 2cca06789a8576e1c13a46c89de22c52f23129c8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 17:03:04 +0800 Subject: [PATCH 01/12] fix --- server/websocket/internal/logic/ws_reuse_last_connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 24fd174e..4a328660 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -67,5 +67,5 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) { // 获取用户拼接部分(复用标识用到) func getUserJoinPart(userId, guestId int64) string { - return fmt.Sprintf("|%d_%d", userId, guestId) + return fmt.Sprintf("|_%d_%d_|", userId, guestId) } From b2460bbc87789c09e1b523e27d211334a405e5ef Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 17:35:43 +0800 Subject: [PATCH 02/12] fix --- .../internal/logic/loginnotifylogic.go | 31 ++++++++++++++++--- .../logic/registeraccountnotifylogic.go | 31 ++++++++++++++++--- server/websocket/internal/types/types.go | 18 ++--------- .../internal/websocket_data/notify_data.go | 8 +++++ server_api/websocket.api | 16 ++-------- 5 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 server/websocket/internal/websocket_data/notify_data.go diff --git a/server/websocket/internal/logic/loginnotifylogic.go b/server/websocket/internal/logic/loginnotifylogic.go index 97c442f9..a532764e 100644 --- a/server/websocket/internal/logic/loginnotifylogic.go +++ b/server/websocket/internal/logic/loginnotifylogic.go @@ -2,9 +2,13 @@ package logic //登录回调 import ( + "encoding/json" "fusenapi/constants" + "fusenapi/server/websocket/internal/websocket_data" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/encryption_decryption" + "time" "context" @@ -33,10 +37,29 @@ func NewLoginNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Login // } func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { - if req.Data.WebsocketConnId == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,连接标识不能为空") + if req.Data == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "data is empty") } - value, ok := mapConnPool.Load(req.Data.WebsocketConnId) + //解密数据 + data, err := encryption_decryption.CBCDecrypt(req.Data) + if err != nil { + logx.Error("解密失败:", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") + } + var parseInfo websocket_data.NotifyData + if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { + logx.Error("failed to parse json data:", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") + } + if parseInfo.WebsocketConnectId == "" { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") + } + now := time.Now().UTC().Unix() + //请求时间前后20秒都会失效 + if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") + } + value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } @@ -46,7 +69,7 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误") } //发送消息到出口缓冲池 - ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_LOGIN_NOTIFY, req.Data.Info)) + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_LOGIN_NOTIFY, parseInfo.Data)) return resp.SetStatusWithMessage(basic.CodeOK, "success") } diff --git a/server/websocket/internal/logic/registeraccountnotifylogic.go b/server/websocket/internal/logic/registeraccountnotifylogic.go index c72aa4ae..278c2a13 100644 --- a/server/websocket/internal/logic/registeraccountnotifylogic.go +++ b/server/websocket/internal/logic/registeraccountnotifylogic.go @@ -2,9 +2,13 @@ package logic //注册帐号回调 import ( + "encoding/json" "fusenapi/constants" + "fusenapi/server/websocket/internal/websocket_data" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/encryption_decryption" + "time" "context" @@ -33,10 +37,29 @@ func NewRegisterAccountNotifyLogic(ctx context.Context, svcCtx *svc.ServiceConte // } func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAccountNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { - if req.Data.WebsocketConnId == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,连接标识不能为空") + if req.Data == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "data is empty") } - value, ok := mapConnPool.Load(req.Data.WebsocketConnId) + //解密数据 + data, err := encryption_decryption.CBCDecrypt(req.Data) + if err != nil { + logx.Error("解密失败:", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") + } + var parseInfo websocket_data.NotifyData + if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { + logx.Error("failed to parse json data:", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") + } + if parseInfo.WebsocketConnectId == "" { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") + } + now := time.Now().UTC().Unix() + //请求时间前后20秒都会失效 + if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") + } + value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } @@ -46,7 +69,7 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc return resp.SetStatusWithMessage(basic.CodeServiceErr, "断言连接错误") } //发送消息到出口缓冲池 - ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_REGISTER_NOTIFY, req.Data.Info)) + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_REGISTER_NOTIFY, parseInfo.Data)) return resp.SetStatusWithMessage(basic.CodeOK, "success") } diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index aed31ca9..d409d63a 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -13,25 +13,11 @@ type RenderNotifyReq struct { } type RegisterAccountNotifyReq struct { - Data RegisterAccountData `json:"data"` - Time int64 `json:"time,optional"` //utc时间戳(用于验证签名) - Sign string `json:"sign,optional"` //签名 -} - -type RegisterAccountData struct { - WebsocketConnId string `json:"websocket_conn_id"` //连接标识 - Info map[string]interface{} `json:"info"` + Data string `json:"data"` //aes_cbc加密密文 } type LoginNotifyReq struct { - Data LoginNotifyData `json:"data"` - Time int64 `json:"time,optional"` //utc时间戳(用于验证签名) - Sign string `json:"sign,optional"` //签名 -} - -type LoginNotifyData struct { - WebsocketConnId string `json:"websocket_conn_id"` //连接标识 - Info map[string]interface{} `json:"info"` + Data string `json:"data"` //aes_cbc加密密文 } type Request struct { diff --git a/server/websocket/internal/websocket_data/notify_data.go b/server/websocket/internal/websocket_data/notify_data.go new file mode 100644 index 00000000..67c627ba --- /dev/null +++ b/server/websocket/internal/websocket_data/notify_data.go @@ -0,0 +1,8 @@ +package websocket_data + +// 请求回调接口数据(登录|注册) +type NotifyData struct { + WebsocketConnectId string `json:"websocket_connect_id"` //websocket连接唯一标识 + RequestTime int64 `json:"request_time"` //请求回调时的utc时间 + Data interface{} `json:"data"` //其他数据 +} diff --git a/server_api/websocket.api b/server_api/websocket.api index fd856c33..c37ec39a 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -32,21 +32,9 @@ type RenderNotifyReq { } //注册回调 type RegisterAccountNotifyReq { - Data RegisterAccountData `json:"data"` - Time int64 `json:"time,optional"` //utc时间戳(用于验证签名) - Sign string `json:"sign,optional"` //签名 -} -type RegisterAccountData { - WebsocketConnId string `json:"websocket_conn_id"` //连接标识 - Info map[string]interface{} `json:"info"` + Data string `json:"data"` //aes_cbc加密密文 } //登录回调 type LoginNotifyReq { - Data LoginNotifyData `json:"data"` - Time int64 `json:"time,optional"` //utc时间戳(用于验证签名) - Sign string `json:"sign,optional"` //签名 -} -type LoginNotifyData { - WebsocketConnId string `json:"websocket_conn_id"` //连接标识 - Info map[string]interface{} `json:"info"` + Data string `json:"data"` //aes_cbc加密密文 } \ No newline at end of file From 5443ad654cf1da03519a22de0c4b5cbc5c925b12 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 23 Aug 2023 17:51:51 +0800 Subject: [PATCH 03/12] =?UTF-8?q?fix:=E8=A3=81=E5=89=AA=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/uploadfilebackendlogic.go | 3 + server/upload/internal/types/types.go | 4 + server_api/upload.api | 4 + utils/file/upload.go | 77 +++++++++++++------ 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/server/upload/internal/logic/uploadfilebackendlogic.go b/server/upload/internal/logic/uploadfilebackendlogic.go index 8e817639..6bd578e1 100644 --- a/server/upload/internal/logic/uploadfilebackendlogic.go +++ b/server/upload/internal/logic/uploadfilebackendlogic.go @@ -91,6 +91,9 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendR UserId: userId, GuestId: guestId, Source: req.Source, + Metadata: req.Metadata, + Refresh: req.Refresh, + ResourceId: req.ResourceId, }) if err != nil { diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index b633d713..665d70db 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -40,6 +40,8 @@ type UploadFileBackendReq struct { FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息 Metadata string `form:"meta_data,optional"` // 上传文件额外信息 Source string `form:"source"` // 上传来源 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 + ResourceId string `form:"resource_id,optional"` // 资源ID } type UploadFilesReq struct { @@ -47,6 +49,8 @@ type UploadFilesReq struct { UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 UploadInfo string `form:"upload_info"` // 上传信息 json Source string `form:"source"` // 上传来源 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 + ResourceId string `form:"resource_id,optional"` // 资源ID } type UploadCallbackReq struct { diff --git a/server_api/upload.api b/server_api/upload.api index 5711e58c..092a5e45 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -89,6 +89,8 @@ type ( FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息 Metadata string `form:"meta_data,optional"` // 上传文件额外信息 Source string `form:"source"` // 上传来源 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 + ResourceId string `form:"resource_id,optional"` // 资源ID } UploadFilesReq { @@ -96,6 +98,8 @@ type ( UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 UploadInfo string `form:"upload_info"` // 上传信息 json Source string `form:"source"` // 上传来源 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 + ResourceId string `form:"resource_id,optional"` // 资源ID } UploadCallbackReq { UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 diff --git a/utils/file/upload.go b/utils/file/upload.go index 89b84a44..9991abaa 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -70,12 +70,14 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er var uploadBaseRes = UploadBaseRes{} + // 是否强制刷新 var refresh bool - if req.ResourceId != "" { - refresh = true resourceId = req.ResourceId } + if req.Refresh == 1 { + refresh = true + } err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource @@ -198,15 +200,28 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro var uploadBaseRes = UploadBaseRes{} - err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error { + // 是否强制刷新 + var refresh bool + if req.ResourceId != "" { + resourceId = req.ResourceId + } + if req.Refresh == 1 { + refresh = true + } + + err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource - err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error - // resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId) - if err == nil && resourceInfo.ResourceId != "" { - uploadBaseRes.Status = 1 - uploadBaseRes.ResourceId = resourceId - uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl - } else { + if !refresh { + err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error + if err == nil && resourceInfo.ResourceId != "" { + uploadBaseRes.Status = 1 + uploadBaseRes.ResourceId = resourceId + uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl + } else { + refresh = true + } + } + if refresh { contentType := http.DetectContentType(req.FileByte) // 创建S3对象存储请求 s3req, _ = svc.PutObjectRequest( @@ -235,19 +250,35 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now().UTC() - err = tx.Create(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &req.Metadata, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + if refresh { + err = tx.Save(&gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &req.Metadata, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + }).Error + } else { + err = tx.Create(&gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &req.Metadata, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + }).Error + } if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") return err From d349fe3197d027ccd874fda629516bd76eeebd27 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:16:12 +0800 Subject: [PATCH 04/12] fix --- server/websocket/internal/logic/loginnotifylogic.go | 4 ++++ server/websocket/internal/logic/registeraccountnotifylogic.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/server/websocket/internal/logic/loginnotifylogic.go b/server/websocket/internal/logic/loginnotifylogic.go index a532764e..024880a4 100644 --- a/server/websocket/internal/logic/loginnotifylogic.go +++ b/server/websocket/internal/logic/loginnotifylogic.go @@ -46,11 +46,13 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { 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 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败") diff --git a/server/websocket/internal/logic/registeraccountnotifylogic.go b/server/websocket/internal/logic/registeraccountnotifylogic.go index 278c2a13..74da6240 100644 --- a/server/websocket/internal/logic/registeraccountnotifylogic.go +++ b/server/websocket/internal/logic/registeraccountnotifylogic.go @@ -46,11 +46,13 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { 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 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败") From 41909b7defa290ebf506066e568cb3f3b3ff91bb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:18:44 +0800 Subject: [PATCH 05/12] fix --- server/websocket/internal/logic/rendernotifylogic.go | 2 +- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 9b6ff45a..89405427 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -88,7 +88,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a }) //发送处理并删除任务 ws.deleteRenderTask(renderImageControlChanItem{ - Option: 0, //0删除 1添加 + Option: 0, //0删除 1添加 2修改耗时属性 TaskId: req.TaskId, RenderNotifyImageUrl: uploadRes.ResourceUrl, }) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 1a4587e5..dc9b3b46 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -154,7 +154,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { //########################################### //把需要渲染的图片任务加进去 w.createRenderTask(renderImageControlChanItem{ - Option: 1, //0删除 1添加 + Option: 1, //0删除 1添加 2修改耗时属性 TaskId: taskId, RenderId: renderImageData.RenderId, }) From 810949c9d860de88ac9bb6785eb7d2d36067b483 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:34:01 +0800 Subject: [PATCH 06/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index cab7f28e..82b1bb74 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -93,7 +93,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) logx.Error("http upgrade websocket err:", err) return } - defer conn.Close() //鉴权不成功后断开 var ( userInfo *auth.UserInfo @@ -103,11 +102,13 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) if !isAuth { //未授权响应消息 l.unAuthResponse(conn) + conn.Close() return } //设置连接 ws, err := l.setConnPool(conn, *userInfo) if err != nil { + conn.Close() return } defer ws.close() @@ -249,7 +250,6 @@ func (w *wsConnectItem) heartbeat() { //发送心跳信息 if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil { logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err) - w.close() return } } From c92944f0dcf8d4c74ee27f20b3dad02943bdf52a Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 23 Aug 2023 18:38:51 +0800 Subject: [PATCH 07/12] =?UTF-8?q?fix:=E8=A3=81=E5=89=AA=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/curl/client_resty.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/curl/client_resty.go b/utils/curl/client_resty.go index a131a253..8542ea80 100644 --- a/utils/curl/client_resty.go +++ b/utils/curl/client_resty.go @@ -65,7 +65,7 @@ type ( // PostJson请求 func (c *defaultClient) PostJson(jsonData interface{}, res interface{}) error { - logc.Infof(c.ctx, "客户端名称 Client PostJson jsonData:%+v", jsonData) + //logc.Infof(c.ctx, "客户端名称 Client PostJson jsonData:%+v", jsonData) logc.Infof(c.ctx, "客户端名称 请求开始时间:%+v", time.Now().UTC()) resp, err := c.client. From db315acceea198e578ca6c6e2f5056e1cda42547 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 11:03:33 +0800 Subject: [PATCH 08/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 82b1bb74..b722f1bc 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -206,6 +206,8 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a if !userInfo.IsUser() && !userInfo.IsGuest() { return false, nil } + userInfo.UserId = 39 + userInfo.GuestId = 39 return true, userInfo } return false, nil From 002444ff82cc0ebe54bfc5870e397d46bf3288f3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 11:03:46 +0800 Subject: [PATCH 09/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index b722f1bc..192133a5 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -207,7 +207,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a return false, nil } userInfo.UserId = 39 - userInfo.GuestId = 39 + userInfo.GuestId = 0 return true, userInfo } return false, nil From 6a45b1e1e7027476091e9a76a11559d8f060176d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 11:27:53 +0800 Subject: [PATCH 10/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 192133a5..52f3034d 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -202,15 +202,10 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a logx.Error(err) return false, nil } - //不是登录用户也不是游客 - if !userInfo.IsUser() && !userInfo.IsGuest() { - return false, nil - } - userInfo.UserId = 39 - userInfo.GuestId = 0 return true, userInfo } - return false, nil + //白板用户 + return true, &auth.UserInfo{} } // 鉴权失败通知 From 724b8421674ef722e8370368fea40394969128ce Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 11:38:42 +0800 Subject: [PATCH 11/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 52f3034d..553f4123 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -84,7 +84,10 @@ type wsConnectItem struct { func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) { //把子协议携带的token设置到标准token头信息中 token := r.Header.Get("Sec-Websocket-Protocol") - r.Header.Set("Authorization", "Bearer "+token) + //有token是正常用户,无则是白板用户,也可以连接 + if token != "" { + r.Header.Set("Authorization", "Bearer "+token) + } //设置Sec-Websocket-Protocol upgrader.Subprotocols = []string{token} //升级websocket From 2c41f590640457334aed14097e8e78fb90960110 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 11:43:16 +0800 Subject: [PATCH 12/12] fix --- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 553f4123..9c2de077 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -87,9 +87,9 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) //有token是正常用户,无则是白板用户,也可以连接 if token != "" { r.Header.Set("Authorization", "Bearer "+token) + //设置Sec-Websocket-Protocol + upgrader.Subprotocols = []string{token} } - //设置Sec-Websocket-Protocol - upgrader.Subprotocols = []string{token} //升级websocket conn, err := upgrader.Upgrade(w, r, nil) if err != nil {