From 95df7ccd04dde7561900c1b12e85bed8318880a0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 11:44:47 +0800 Subject: [PATCH 01/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 0f65ccbb..86d49b16 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -167,6 +167,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use l.sendGetUniqueIdErrResponse(conn) return wsConnectItem{}, err } + //传入绑定的wid判断是否可重用 if oldWid != "" { for i := 0; i < 1; i++ { //解析传入的wid是不是属于自己的用户的 From e14fd8b28680338357d0e0bf8a41af2aa3dec148 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 18 Oct 2023 11:48:32 +0800 Subject: [PATCH 02/17] =?UTF-8?q?feat:=E5=90=88=E5=9B=BE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?debug=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/image_handle.go | 31 +++++++++++++++++++--------- utils/auth/user.go | 6 ++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index f5036756..170eeb1c 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -136,6 +136,7 @@ type ( Metadata *string DiffTimeLogoCombine int64 DiffTimeUploadFile int64 + DebugData *auth.DebugData `json:"debug_data"` } ) type TemplateTagColor struct { @@ -144,6 +145,7 @@ type TemplateTagColor struct { } func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { + var resp = &LogoCombineRes{} logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl) if logoResourceId == "" { return nil, errors.New("invalid logo url") @@ -167,10 +169,12 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq resourceModel := gmodel.NewFsResourceModel(l.MysqlConn) resourceInfo, err := resourceModel.FindOneById(ctx, resourceId) if err == nil && resourceInfo.ResourceId != "" { - return &LogoCombineRes{ - ResourceId: resourceId, - ResourceUrl: resourceInfo.ResourceUrl, - }, nil + if in.Debug == nil || (in.Debug != nil && in.Debug.IsCache == 1) { + return &LogoCombineRes{ + ResourceId: resourceId, + ResourceUrl: resourceInfo.ResourceUrl, + }, nil + } } else { if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { @@ -308,12 +312,19 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq return nil, err } - return &LogoCombineRes{ - ResourceId: uploadRes.ResourceId, - ResourceUrl: &uploadRes.ResourceUrl, - DiffTimeLogoCombine: diffTimeLogoCombine, - DiffTimeUploadFile: diffTimeUploadFile, - }, nil + resp.ResourceId = uploadRes.ResourceId + resp.ResourceUrl = &uploadRes.ResourceUrl + resp.DiffTimeLogoCombine = diffTimeLogoCombine + resp.DiffTimeUploadFile = diffTimeUploadFile + + if in.Debug != nil { + resp.DebugData = &auth.DebugData{ + DiffTimeLogoCombine: diffTimeLogoCombine, + DiffTimeUploadFile: diffTimeUploadFile, + } + } + + return resp, nil } /* logo合图 */ diff --git a/utils/auth/user.go b/utils/auth/user.go index 8c9e2ca5..b1d43087 100644 --- a/utils/auth/user.go +++ b/utils/auth/user.go @@ -24,6 +24,12 @@ const ( IDTYPE_Guest IDTYPE = 2 ) +// DebugData +type DebugData struct { + DiffTimeLogoCombine int64 `json:"diff_time_logo_combine"` // 合图算法时间 + DiffTimeUploadFile int64 `json:"diff_time_upload_file"` // 合图上传时间 +} + // Debug 相关的结构 type Debug struct { Exp *int64 `json:"exp"` From 86547b9267e0427e0d1890040e858fd7964cbc32 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 18 Oct 2023 11:54:58 +0800 Subject: [PATCH 03/17] =?UTF-8?q?feat:=E5=90=88=E5=9B=BE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?debug=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/internal/logic/logocombinelogic.go | 11 +++++------ service/repositories/image_handle.go | 13 ++++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/server/resource/internal/logic/logocombinelogic.go b/server/resource/internal/logic/logocombinelogic.go index 609a4316..2a601548 100644 --- a/server/resource/internal/logic/logocombinelogic.go +++ b/server/resource/internal/logic/logocombinelogic.go @@ -116,6 +116,7 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth }, ProductTemplateTagGroups: req.TemplateTagGroups, ProductTemplateV2Info: productTemplateV2Info, + Debug: userinfo.Debug, }) if err != nil { @@ -124,10 +125,8 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth // 返回成功的响应和上传URL return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "resource_id": res.ResourceId, - "resource_url": res.ResourceUrl, - "resource_metadata": "", - "diff_time_logo_combine": res.DiffTimeLogoCombine, - "diff_time_upload_file": res.DiffTimeUploadFile, - }) + "resource_id": res.ResourceId, + "resource_url": res.ResourceUrl, + "resource_metadata": "", + }).WithDebug(res.DebugData) } diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 170eeb1c..bde815fa 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -131,12 +131,10 @@ type ( Debug *auth.Debug `json:"debug"` } LogoCombineRes struct { - ResourceId string - ResourceUrl *string - Metadata *string - DiffTimeLogoCombine int64 - DiffTimeUploadFile int64 - DebugData *auth.DebugData `json:"debug_data"` + ResourceId string + ResourceUrl *string + Metadata *string + DebugData *auth.DebugData `json:"debug_data"` } ) type TemplateTagColor struct { @@ -314,9 +312,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq resp.ResourceId = uploadRes.ResourceId resp.ResourceUrl = &uploadRes.ResourceUrl - resp.DiffTimeLogoCombine = diffTimeLogoCombine - resp.DiffTimeUploadFile = diffTimeUploadFile - if in.Debug != nil { resp.DebugData = &auth.DebugData{ DiffTimeLogoCombine: diffTimeLogoCombine, From 616fc938cb4f6033ab4b985a5da4e2b83b24a979 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 11:57:26 +0800 Subject: [PATCH 04/17] fix --- server/websocket/internal/logic/ws_render_image.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 9cd04c9a..9db76b29 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -10,6 +10,7 @@ import ( "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/service/repositories" + "fusenapi/utils/auth" "fusenapi/utils/curl" "fusenapi/utils/hash" "fusenapi/utils/websocket_data" @@ -245,7 +246,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe return } //发送合图完毕阶段消息 - w.sendCombineImageStepResponseMessage(renderImageData.RenderId, renderImageData.RequestId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DiffTimeLogoCombine, res.DiffTimeUploadFile) + w.sendCombineImageStepResponseMessage(renderImageData.RenderId, renderImageData.RequestId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DebugData) //获取唯一id taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element) //查询有没有缓存的资源,有就返回 @@ -467,17 +468,17 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web // ****************************下面的发送消息的********************************* // 发送合图完毕阶段通知消息 -func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId, combineTime, uploadTime int64) { +func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId int64, debugData *auth.DebugData) { if w.debug == nil { return } combineTakesTime := "cache" uploadCombineImageTakesTime := "cache" - if combineTime > 0 { - combineTakesTime = fmt.Sprintf("%dms", combineTime) + if debugData.DiffTimeLogoCombine > 0 { + combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine) } - if uploadTime > 0 { - uploadCombineImageTakesTime = fmt.Sprintf("%dms", uploadTime) + if debugData.DiffTimeUploadFile > 0 { + uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile) } w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{ RenderId: renderId, From 5a173a491c91ce4b4c909075b75149580a7a3c78 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 12:02:04 +0800 Subject: [PATCH 05/17] fix --- server/websocket/internal/logic/ws_render_image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 9db76b29..98abfa7b 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -133,7 +133,7 @@ func (w *wsConnectItem) consumeRenderImageData() { }() select { case <-w.extendRenderProperty.renderCtx.Done(): - panic("=========检测到模板标签/颜色变化,渲染取消旧的任务=======") + panic("检测到模板标签/颜色变化,渲染取消旧的任务") case <-tmpChan: return } From 2ab8a4b21330152054a0c5cd6ac6ba596e6c98e1 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 18 Oct 2023 12:10:29 +0800 Subject: [PATCH 06/17] =?UTF-8?q?feat:=E5=90=88=E5=9B=BE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?debug=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constants/invoice_html.go | 17 ++++++++++++----- service/repositories/order.go | 30 +++++++++++------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/constants/invoice_html.go b/constants/invoice_html.go index 6e4417a8..6fddf30c 100644 --- a/constants/invoice_html.go +++ b/constants/invoice_html.go @@ -196,7 +196,7 @@ const INVOICE_TEMPLATE_01 = ` const INVOICE_TEMPLATE_02 = ` - +
@@ -221,7 +221,7 @@ const INVOICE_TEMPLATE_02 = ` ` const INVOICE_TEMPLATE_03 = ` -
Bill To: Invoice No. #%v
+
@@ -242,7 +242,7 @@ const INVOICE_TEMPLATE_0301 = ` ` const INVOICE_TEMPLATE_04 = ` -
Product Name Price
+
@@ -271,7 +271,7 @@ const INVOICE_TEMPLATE_04 = ` ` const INVOICE_TEMPLATE_05 = ` -
Subtotal %v
+
@@ -287,7 +287,14 @@ const INVOICE_TEMPLATE_05 = ` ` const INVOICE_TEMPLATE_06 = ` - + diff --git a/service/repositories/order.go b/service/repositories/order.go index bdf5f037..bd0ca6c7 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -365,11 +365,15 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic var city string var street string var state string + var suite string + var zipCode string if ress.OrderDetail.DeliveryAddress != nil { name = fmt.Sprintf("%s %s", ress.OrderDetail.DeliveryAddress.FirstName, ress.OrderDetail.DeliveryAddress.LastName) street = ress.OrderDetail.DeliveryAddress.Street city = ress.OrderDetail.DeliveryAddress.City state = ress.OrderDetail.DeliveryAddress.State + suite = ress.OrderDetail.DeliveryAddress.Suite + zipCode = ress.OrderDetail.DeliveryAddress.ZipCode } var products string @@ -380,7 +384,7 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic var productsInfo = fmt.Sprintf(model00301, orderProduct.ProductName, price, orderProduct.PurchaseQuantity.Current, priceTotal) products = products + productsInfo } - model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, "", products) + model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, products) var subtotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentAmount.(string)) var taxStr = "0.00" @@ -396,22 +400,16 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic // 生成收据发票--首款 if receiptSnsDeposit != "" { - v1 := receiptSnsDeposit - v2 := name - v3 := ctimeDate - v4 := street - v5 := city - v6 := state - model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, "", v1, v2, v3, v4, v5, v6) + model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode) v7 := "Deposit Requested" v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(string)) v9 := "Deposit Due" v10 := v8 - model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, "", subtotal, tax, total, v7, v8, v9, v10) + model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10) cardSn := "****" + *orderTradeDeposit.CardSn - model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, "", *orderTradeDeposit.CardBrand, cardSn) + model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn) var content = model001 + model002 + model003 + model004 + model005 + model006 @@ -456,22 +454,16 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic // 生成收据发票--尾款 if receiptSnsFinal != "" { - v1 := receiptSnsFinal - v2 := name - v3 := ctimeDate - v4 := street - v5 := city - v6 := state - model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, "", v1, v2, v3, v4, v5, v6) + model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode) v7 := "Balance Requested" v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(string)) v9 := "Balance Due" v10 := v8 - model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, "", subtotal, tax, total, v7, v8, v9, v10) + model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10) cardSn := "****" + *orderTradeFinal.CardSn - model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, "", *orderTradeDeposit.CardBrand, cardSn) + model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn) var content = model001 + model002 + model003 + model004 + model005 + model006 base64, err := pdf.HtmlToPdfBase64(content, "html") if err != nil { From 56f17f1bd83c6fcc2cd966d21897f6897f4322e7 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 12:21:11 +0800 Subject: [PATCH 07/17] fix --- server/websocket/internal/logic/ws_render_image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 98abfa7b..2d072cad 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -133,7 +133,7 @@ func (w *wsConnectItem) consumeRenderImageData() { }() select { case <-w.extendRenderProperty.renderCtx.Done(): - panic("检测到模板标签/颜色变化,渲染取消旧的任务") + panic("检测到模板标签/颜色/logo变化,渲染取消旧的任务") case <-tmpChan: return } From e94917a9d248e29bb6846c6f889f0d23e87e7a75 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 18 Oct 2023 14:01:46 +0800 Subject: [PATCH 08/17] =?UTF-8?q?feat:=E5=90=88=E5=9B=BE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?debug=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/logic/uploadlogologic.go | 1 + service/repositories/image_handle.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index 05d5b0be..7a2759ad 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -174,6 +174,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{ LogoUrl: logoUrl, Version: l.svcCtx.Config.BLMService.Version, + Debug: userinfo.Debug, }) if err != nil { diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index bde815fa..0090dd50 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -68,8 +68,9 @@ type ( /* logo信息 */ type ( LogoInfoSetReq struct { - LogoUrl string `json:"logo_url"` - Version string `json:"version"` + LogoUrl string `json:"logo_url"` + Version string `json:"version"` + Debug *auth.Debug `json:"debug"` } LogoInfoSetRes struct { Res string `json:"res"` @@ -90,6 +91,10 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq postMap["logo_url"] = in.LogoUrl postMap["version"] = in.Version + if in.Debug != nil && in.Debug.IsAllTemplateTag == 1 { + postMap["is_all_template"] = "1" + } + logc.Infof(ctx, "算法请求--LOGO基础信息--开始时间:%v", time.Now().UTC()) err := curl.NewClient(ctx, &curl.Config{ BaseUrl: bLMServicePort, From 90e0169eb7afee83f628a62a728b9138418cc430 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 14:35:33 +0800 Subject: [PATCH 09/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 5 +++-- utils/websocket_data/render_data.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 86d49b16..45aedd4c 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -452,8 +452,9 @@ func (w *wsConnectItem) sendToInChan(data []byte) { // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ - T: msgType, - D: data, + T: msgType, + D: data, + OpenDebug: w.debug != nil, } b, _ := json.Marshal(d) return b diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index bcca7309..22fca565 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -4,8 +4,9 @@ import "fusenapi/constants" // websocket数据交互基本数据类型 type DataTransferData struct { - T constants.Websocket `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 + T constants.Websocket `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 + OpenDebug bool `json:"open_debug"` //是否开启debug } // websocket接受要云渲染处理的数据 From 57e6b0227ffbcf3c605efc624a764af4138af86e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 14:37:18 +0800 Subject: [PATCH 10/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 6 +++--- utils/websocket_data/render_data.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 45aedd4c..93817c8f 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -452,9 +452,9 @@ func (w *wsConnectItem) sendToInChan(data []byte) { // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ - T: msgType, - D: data, - OpenDebug: w.debug != nil, + T: msgType, + D: data, + Debug: w.debug != nil, } b, _ := json.Marshal(d) return b diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 22fca565..601799f1 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -4,9 +4,9 @@ import "fusenapi/constants" // websocket数据交互基本数据类型 type DataTransferData struct { - T constants.Websocket `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 - OpenDebug bool `json:"open_debug"` //是否开启debug + T constants.Websocket `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 + Debug bool `json:"debug"` //是否开启debug } // websocket接受要云渲染处理的数据 From fbbf6b984fa2b29574e60b6cd49b1c5222455f50 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 14:40:50 +0800 Subject: [PATCH 11/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 7 +++---- utils/websocket_data/base_data.go | 3 ++- utils/websocket_data/render_data.go | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 93817c8f..4d851642 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -238,7 +238,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use if isFirefoxBrowser { time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) } - ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId})) + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId, Debug: ws.debug != nil})) //发送累加统计连接书 increaseWebsocketConnectCount() return ws, nil @@ -452,9 +452,8 @@ func (w *wsConnectItem) sendToInChan(data []byte) { // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ - T: msgType, - D: data, - Debug: w.debug != nil, + T: msgType, + D: data, } b, _ := json.Marshal(d) return b diff --git a/utils/websocket_data/base_data.go b/utils/websocket_data/base_data.go index c3799fa4..2951c394 100644 --- a/utils/websocket_data/base_data.go +++ b/utils/websocket_data/base_data.go @@ -2,7 +2,8 @@ package websocket_data // 基础连接成功返回 type ConnectSuccessMsg struct { - Wid string `json:"wid"` + Wid string `json:"wid"` //websocket连接唯一标识 + Debug bool `json:"debug"` //是否开启debug } // 连接失败 diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 601799f1..bcca7309 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -4,9 +4,8 @@ import "fusenapi/constants" // websocket数据交互基本数据类型 type DataTransferData struct { - T constants.Websocket `json:"t"` //消息类型 - D interface{} `json:"d"` //传递的消息 - Debug bool `json:"debug"` //是否开启debug + T constants.Websocket `json:"t"` //消息类型 + D interface{} `json:"d"` //传递的消息 } // websocket接受要云渲染处理的数据 From 79ce15a92a31ea110d6fb6ec33216380e4fa18d5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 14:59:21 +0800 Subject: [PATCH 12/17] 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 4d851642..13d4a78a 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -239,7 +239,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) } ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId, Debug: ws.debug != nil})) - //发送累加统计连接书 + //发送累加统计连接数 increaseWebsocketConnectCount() return ws, nil } From 379230dd395006294c17651f4e181a5fc6c27f2a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 15:05:38 +0800 Subject: [PATCH 13/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 13d4a78a..13deb2b6 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -225,12 +225,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use }, debug: userInfo.Debug, } - //先设置下debug(后面要删掉) - ws.debug = &auth.Debug{ - Exp: &userInfo.Exp, - IsCache: 1, - IsAllTemplateTag: 0, - } //保存连接 mapConnPool.Store(uniqueId, ws) //非白板用户,需要为这个用户建立map索引便于通过用户查询 From 6de13a61f76a89ec89aad39cc167cbadccf24c76 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 15:10:45 +0800 Subject: [PATCH 14/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 13deb2b6..003ddf06 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -323,6 +323,10 @@ func (w *wsConnectItem) heartbeat() { w.close() return } + //查看debug的时间是否过期 + if w.debug != nil && w.debug.Exp != nil && *w.debug.Exp < time.Now().UTC().Unix() { + w.debug = nil + } //发送心跳信息 if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil { logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err) From 22f9bf7165e2b331d050f3044dd399c7fdfc3914 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 15:28:47 +0800 Subject: [PATCH 15/17] fix --- .../internal/logic/datatransferlogic.go | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 003ddf06..b7b1261e 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -104,14 +104,28 @@ type wsConnectItem struct { // 请求建立连接,升级websocket协议 func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.ResponseWriter, r *http.Request) { //把子协议携带的token设置到标准token头信息中 - token := r.Header.Get("Sec-Websocket-Protocol") + tokens := r.Header.Get("Sec-Websocket-Protocol") oldWid := req.Wid oldWid = strings.Trim(oldWid, " ") //有token是正常用户,无则是白板用户,也可以连接 - if token != "" { + if tokens != "" { + token := "" + debugToken := "" + tokenSlice := strings.Split(tokens, ",") + switch len(tokenSlice) { + case 1: + token = strings.Trim(tokenSlice[0], " ") + case 2: + token = strings.Trim(tokenSlice[0], " ") + debugToken = strings.Trim(tokenSlice[1], " ") + r.Header.Set("Debug-Token", "Bearer "+debugToken) + default: + logx.Error("invalid ws token:", tokens) + return + } r.Header.Set("Authorization", "Bearer "+token) //设置Sec-Websocket-Protocol - upgrader.Subprotocols = []string{token} + upgrader.Subprotocols = []string{tokens} } //判断下是否火狐浏览器(获取浏览器第一条消息返回有收不到的bug需要延迟1秒) userAgent := r.Header.Get("User-Agent") From 8da41cee3b49c3b7306a0c062fa052f813e8149f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 15:32:58 +0800 Subject: [PATCH 16/17] 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 b7b1261e..96e05fb3 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -118,7 +118,7 @@ func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.Resp case 2: token = strings.Trim(tokenSlice[0], " ") debugToken = strings.Trim(tokenSlice[1], " ") - r.Header.Set("Debug-Token", "Bearer "+debugToken) + r.Header.Set("Debug-Token", debugToken) default: logx.Error("invalid ws token:", tokens) return From 6c94bc29c9407204c073f8260a8717f816d2ceb6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 18 Oct 2023 15:38:26 +0800 Subject: [PATCH 17/17] fix --- server/websocket/internal/logic/datatransferlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 96e05fb3..92e264c1 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -284,6 +284,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a // 解析JWT token,并对空用户进行判断 userInfo, err := basic.ParseJwtToken(r, l.svcCtx) if err != nil { + logx.Error("未授权:", err.Error()) return false, nil } if userInfo.UserId > 0 {
Payment Method: Notes: