fix
This commit is contained in:
parent
d2f24772ca
commit
4dce0d7087
|
@ -59,53 +59,65 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!")
|
||||
}
|
||||
//重新赋值(很重要)
|
||||
req.TaskId = info.TaskId
|
||||
wid := info.Wid
|
||||
renderId := info.RenderId
|
||||
unityRenderBeginTime := info.RenderBeginTime
|
||||
//存base64打印测试
|
||||
/* f, _ := os.Create("b.txt")
|
||||
defer f.Close()
|
||||
f.WriteString(req.Image)*/
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
Ctx: l.ctx,
|
||||
MysqlConn: l.svcCtx.MysqlConn,
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
//获取连接
|
||||
value, wsConnectOk := mapConnPool.Load(wid)
|
||||
if req.Code == 0 { //渲染成功
|
||||
//上传文件
|
||||
var upload = file.Upload{
|
||||
Ctx: l.ctx,
|
||||
MysqlConn: l.svcCtx.MysqlConn,
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
}
|
||||
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
|
||||
Source: "unity cloud render",
|
||||
FileHash: info.TaskId,
|
||||
FileData: req.Image,
|
||||
Metadata: "",
|
||||
UploadBucket: 1,
|
||||
ApiType: 2,
|
||||
UserId: req.UserId,
|
||||
GuestId: req.GuestId,
|
||||
FileByte: nil,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("渲染回调上传文件失败:", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
||||
}
|
||||
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
|
||||
if wsConnectOk {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
logx.Error("渲染回调断言websocket连接失败")
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "渲染回调断言websocket连接失败")
|
||||
}
|
||||
//发送到出口
|
||||
ws.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: uploadRes.ResourceUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
UnityRenderTakesTime: fmt.Sprintf("%dms", unityRenderEndTime-unityRenderBeginTime),
|
||||
UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime),
|
||||
},
|
||||
})
|
||||
logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:but websocket connect not found")
|
||||
}
|
||||
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
|
||||
Source: "unity cloud render",
|
||||
FileHash: req.TaskId,
|
||||
FileData: req.Image,
|
||||
Metadata: "",
|
||||
UploadBucket: 1,
|
||||
ApiType: 2,
|
||||
UserId: req.UserId,
|
||||
GuestId: req.GuestId,
|
||||
FileByte: nil,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("渲染回调上传文件失败:", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
||||
}
|
||||
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
|
||||
if value, ok := mapConnPool.Load(wid); ok {
|
||||
//渲染失败走下面
|
||||
if wsConnectOk {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
logx.Error("渲染回调断言websocket连接失败")
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "渲染回调断言websocket连接失败")
|
||||
}
|
||||
//发送到出口
|
||||
ws.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderId,
|
||||
Image: uploadRes.ResourceUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
UnityRenderTakesTime: fmt.Sprintf("%dms", unityRenderEndTime-unityRenderBeginTime),
|
||||
UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime),
|
||||
},
|
||||
})
|
||||
//发送错误信息给前端
|
||||
ws.renderErrResponse(renderId, info.TemplateTag, info.TaskId, "unity错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
|
||||
}
|
||||
logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
||||
|
|
|
@ -372,6 +372,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
|
|||
Wid: w.uniqueId,
|
||||
RenderId: info.RenderId,
|
||||
RenderBeginTime: time.Now().UTC().UnixMilli(),
|
||||
TemplateTag: info.RenderData.TemplateTag,
|
||||
}
|
||||
temIdBytes, _ := json.Marshal(temId)
|
||||
sendData := map[string]interface{}{
|
||||
|
|
|
@ -6,14 +6,16 @@ import (
|
|||
)
|
||||
|
||||
type RenderNotifyReq struct {
|
||||
TaskId string `json:"task_id"` //任务id + " " + wid的结合字符串
|
||||
TaskId string `json:"task_id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
Code int `json:"code,optional"`
|
||||
Msg string `json:"msg,optional"`
|
||||
}
|
||||
|
||||
type CommonNotifyReq struct {
|
||||
Wid string `json:"wid,optional"` //websocket连接标识
|
||||
Wid string `json:"wid,optional"` //websocket连接标识(找ws连接优先级高于user_id和guestid)
|
||||
UserId int64 `json:"user_id,optional"` //用户id
|
||||
GuestId int64 `json:"guest_id,optional"` //游客id
|
||||
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
|
||||
|
@ -42,10 +44,10 @@ type File struct {
|
|||
}
|
||||
|
||||
type Meta struct {
|
||||
TotalCount int64 `json:"totalCount"`
|
||||
PageCount int64 `json:"pageCount"`
|
||||
CurrentPage int `json:"currentPage"`
|
||||
PerPage int `json:"perPage"`
|
||||
TotalCount int64 `json:"total_count"`
|
||||
PageCount int64 `json:"page_count"`
|
||||
CurrentPage int `json:"current_page"`
|
||||
PerPage int `json:"per_page"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
|
|
|
@ -26,6 +26,8 @@ type RenderNotifyReq {
|
|||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
Image string `json:"image"`
|
||||
Code int `json:"code,optional"`
|
||||
Msg string `json:"msg,optional"`
|
||||
}
|
||||
//通用回调接口
|
||||
type CommonNotifyReq {
|
||||
|
|
|
@ -74,4 +74,5 @@ type ToUnityIdStruct struct {
|
|||
Wid string `json:"wid"`
|
||||
RenderId string `json:"render_id"`
|
||||
RenderBeginTime int64 `json:"render_begin_time"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user