fusenapi/server/websocket/internal/logic/ws_err_response.go

82 lines
2.3 KiB
Go
Raw Normal View History

2023-08-24 09:23:41 +00:00
package logic
2023-10-18 09:07:19 +00:00
import (
"encoding/json"
"fusenapi/constants"
"fusenapi/utils/websocket_data"
"github.com/gorilla/websocket"
"time"
)
2023-08-24 09:23:41 +00:00
2023-10-18 09:07:19 +00:00
// 获取唯一标识失败通知
func (l *DataTransferLogic) sendGetUniqueIdErrResponse(conn *websocket.Conn) {
rsp := websocket_data.DataTransferData{
T: constants.WEBSOCKET_CONNECT_ERR,
D: websocket_data.ConnectErrMsg{Message: "err to gen unique id "},
}
b, _ := json.Marshal(rsp)
//先发一条正常信息
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
//发送关闭信息
_ = conn.WriteMessage(websocket.CloseMessage, nil)
}
// 鉴权失败通知
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) {
rsp := websocket_data.DataTransferData{
T: constants.WEBSOCKET_UNAUTH,
D: websocket_data.ConnectUnAuth{Message: errMessage},
}
b, _ := json.Marshal(rsp)
if isFirefoxBrowser {
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
}
//先发一条正常信息
_ = conn.WriteMessage(getWebsocketBaseTransferDataFormat(), b)
//发送关闭信息
_ = conn.WriteMessage(websocket.CloseMessage, nil)
}
// 通用入口数据格式错误
2023-08-24 09:23:41 +00:00
func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) {
2023-10-18 03:03:07 +00:00
if w.debug == nil {
2023-10-16 07:56:02 +00:00
return
2023-10-16 07:05:03 +00:00
}
2023-10-16 07:56:02 +00:00
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, data))
2023-08-24 09:23:41 +00:00
}
// 渲染错误通知
2023-10-11 06:42:49 +00:00
func (w *wsConnectItem) renderErrResponse(renderId, requestId, templateTag, taskId, description string, productId, userId, guestId, templateId, modelId, sizeId, elementModelId int64) {
2023-10-18 03:03:07 +00:00
if w.debug == nil {
2023-10-16 07:56:02 +00:00
return
2023-08-28 10:37:58 +00:00
}
2023-10-16 07:56:02 +00:00
data := make(map[string]interface{})
data["render_id"] = renderId
data["request_id"] = requestId
data["description"] = description
data["template_tag"] = templateTag
data["product_id"] = productId
if taskId != "" {
data["task_id"] = taskId
}
if userId >= 0 {
data["user_id"] = userId
}
if guestId >= 0 {
data["guest_id"] = guestId
}
if templateId > 0 {
data["template_id"] = templateId
}
if modelId > 0 {
data["model_id"] = modelId
}
if sizeId > 0 {
data["size_id"] = sizeId
}
if elementModelId > 0 {
data["element_model_id"] = elementModelId
}
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, data))
2023-08-24 09:23:41 +00:00
}