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

This commit is contained in:
momo 2023-09-22 11:01:03 +08:00
commit d00089c625
3 changed files with 31 additions and 16 deletions

View File

@ -98,22 +98,20 @@ func main() {
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
err := r.ParseMultipartForm(100 << 20)
if err != nil {
logx.Error(err)
}
r.ParseMultipartForm(100 << 20)
// if err != nil {
// logx.Error(err)
// }
// 对/api开头的请求进行反向代理
proxy := httputil.NewSingleHostReverseProxy(apiURL)
proxy.ErrorHandler = func(res http.ResponseWriter, req *http.Request, err error) {
if err != nil {
// 在发生错误时进行处理
logx.Error(err)
logx.Error(res.Header())
res.WriteHeader(http.StatusNotFound) // 返回404状态码
_, err := res.Write([]byte(err.Error()))
if err != nil {
logx.Error(err)
}
}
}
proxy.ServeHTTP(w, r)

View File

@ -192,7 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
userId: userInfo.UserId,
guestId: userInfo.GuestId,
extendRenderProperty: extendRenderProperty{
renderChan: make(chan []byte, renderChanLen),
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
},
}
//保存连接

View File

@ -30,16 +30,26 @@ type renderProcessor struct {
// 云渲染属性
type extendRenderProperty struct {
renderChan chan []byte //渲染消息入口的缓冲队列
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
colorSelectedIndex int //选择颜色索引
templateTag string //模板标签
}
// 处理分发到这里的数据
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
//logx.Info("开始处理渲染任务消息:", string(data))
var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("invalid format of websocket render image message", err)
return
}
select {
case <-w.closeChan: //已经关闭
return
case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
w.extendRenderProperty.colorSelectedIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag
return
}
}
@ -51,26 +61,33 @@ func (w *wsConnectItem) consumeRenderImageData() {
logx.Error("func renderImage err:", err)
}
}()
var data []byte
for {
select {
case <-w.closeChan: //已关闭
return
case data = <-w.extendRenderProperty.renderChan: //消费数据
case data := <-w.extendRenderProperty.renderChan: //消费数据
//属性不同则不发送渲染
if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag {
continue
}
//属性不同则不发送渲染
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.colorSelectedIndex {
continue
}
w.renderImage(data)
}
}
}
// 执行渲染任务
func (w *wsConnectItem) renderImage(data []byte) {
func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) {
//logx.Info("消费渲染数据:", string(data))
var renderImageData websocket_data.RenderImageReqMsg
/*var renderImageData websocket_data.RenderImageReqMsg
if err := json.Unmarshal(data, &renderImageData); err != nil {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
logx.Error("invalid format of websocket render image message", err)
return
}
}*/
if renderImageData.RenderData.Logo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return