fix
This commit is contained in:
		
							parent
							
								
									afe8b26eee
								
							
						
					
					
						commit
						2e4be2800f
					
				@ -1,15 +0,0 @@
 | 
			
		||||
package handler
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fusenapi/server/websocket/internal/logic"
 | 
			
		||||
	"fusenapi/server/websocket/internal/svc"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 | 
			
		||||
	return func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		// 创建一个业务逻辑层实例
 | 
			
		||||
		l := logic.NewDataTransferLogic(r.Context(), svcCtx)
 | 
			
		||||
		l.DataTransfer(w, r)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -8,6 +8,7 @@ import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"fusenapi/constants"
 | 
			
		||||
	"fusenapi/server/websocket/internal/types"
 | 
			
		||||
	"fusenapi/utils/auth"
 | 
			
		||||
	"fusenapi/utils/basic"
 | 
			
		||||
	"fusenapi/utils/encryption_decryption"
 | 
			
		||||
@ -107,7 +108,7 @@ type wsConnectItem struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 请求建立连接,升级websocket协议
 | 
			
		||||
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	origin := r.Header.Get("Origin")
 | 
			
		||||
	//判断是不是允许的跨域
 | 
			
		||||
	if !openDebug {
 | 
			
		||||
@ -119,27 +120,13 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	//把子协议携带的token设置到标准token头信息中
 | 
			
		||||
	secWebsocketProtocol := r.Header.Get("Sec-Websocket-Protocol")
 | 
			
		||||
	oldWid := ""
 | 
			
		||||
	token := r.Header.Get("Sec-Websocket-Protocol")
 | 
			
		||||
	oldWid := req.Wid
 | 
			
		||||
	//有token是正常用户,无则是白板用户,也可以连接
 | 
			
		||||
	if secWebsocketProtocol != "" {
 | 
			
		||||
		s := strings.Split(secWebsocketProtocol, ",")
 | 
			
		||||
		if len(s) != 2 {
 | 
			
		||||
			w.Write([]byte("invalid secWebsocketProtocol param"))
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		//有效token
 | 
			
		||||
		token := strings.Trim(s[0], " ")
 | 
			
		||||
		if token != "empty_token" {
 | 
			
		||||
	if token != "" {
 | 
			
		||||
		r.Header.Set("Authorization", "Bearer "+token)
 | 
			
		||||
		}
 | 
			
		||||
		//有效wid
 | 
			
		||||
		wid := strings.Trim(s[1], " ")
 | 
			
		||||
		if wid != "empty_wid" {
 | 
			
		||||
			oldWid = wid
 | 
			
		||||
		}
 | 
			
		||||
		//设置Sec-Websocket-Protocol
 | 
			
		||||
		upgrader.Subprotocols = []string{secWebsocketProtocol}
 | 
			
		||||
		upgrader.Subprotocols = []string{token}
 | 
			
		||||
	}
 | 
			
		||||
	//判断下是否火狐浏览器(获取浏览器第一条消息返回有收不到的bug需要延迟1秒)
 | 
			
		||||
	userAgent := r.Header.Get("User-Agent")
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,10 @@ import (
 | 
			
		||||
	"fusenapi/utils/basic"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DataTransferReq struct {
 | 
			
		||||
	Wid string `form:"wid"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type RenderNotifyReq struct {
 | 
			
		||||
	TaskId  string `json:"task_id"`
 | 
			
		||||
	UserId  int64  `json:"user_id"`
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ import "basic.api"
 | 
			
		||||
service websocket {
 | 
			
		||||
	//websocket数据交互
 | 
			
		||||
	@handler DataTransferHandler
 | 
			
		||||
	get /api/websocket/data_transfer(request) returns (response);
 | 
			
		||||
	get /api/websocket/data_transfer(DataTransferReq) returns (response);
 | 
			
		||||
	//云渲染完了通知接口
 | 
			
		||||
	@handler RenderNotifyHandler
 | 
			
		||||
	post /api/websocket/render_notify(RenderNotifyReq) returns (response);
 | 
			
		||||
@ -20,6 +20,10 @@ service websocket {
 | 
			
		||||
	post /api/websocket/common_notify(CommonNotifyReq) returns (response);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//websocket数据交互[
 | 
			
		||||
type DataTransferReq {
 | 
			
		||||
	Wid string `form:"wid"`
 | 
			
		||||
}
 | 
			
		||||
//渲染完了通知接口
 | 
			
		||||
type RenderNotifyReq {
 | 
			
		||||
	TaskId  string `json:"task_id"`
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user