Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
c237fe6adc
|
@ -36,7 +36,7 @@ func (l *DebugAuthDeleteLogic) DebugAuthDelete(req *types.RequestAuthDelete, use
|
|||
|
||||
err := l.svcCtx.AllModels.FsUser.DebugAuthDelete(l.ctx, req.Email)
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -88,7 +88,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
user, err := l.svcCtx.AllModels.FsUser.RegisterByGoogleOAuth(l.ctx, token)
|
||||
if err != nil {
|
||||
logx.Error(err, token.TraceId)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
err = FinishRegister(l.svcCtx, user, token)
|
||||
|
@ -117,7 +117,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.Token) // ResetToken
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err)
|
||||
}
|
||||
|
||||
if time.Since(rt.CreateAt) > 30*time.Minute {
|
||||
|
@ -126,7 +126,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
|
||||
// TODO: 存储
|
||||
if rt.OperateType != auth.OpTypeResetToken {
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, "error OperateType: rt.OperateType != auth.OpTypeResetToken")
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, fmt.Errorf("error OperateType: rt.OperateType != auth.OpTypeResetToken"))
|
||||
}
|
||||
|
||||
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
|
||||
|
@ -142,14 +142,14 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err)
|
||||
}
|
||||
|
||||
event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId)
|
||||
err = wevent.CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event)
|
||||
if err != nil {
|
||||
logx.Error(err, rt.TraceId)
|
||||
return resp.SetStatus(basic.CodeResetPasswordErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeResetPasswordErr, err)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -64,13 +64,13 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
|
|||
token, err := googleOauthConfig.Exchange(l.ctx, req.Code)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeApiErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeApiErr, err)
|
||||
}
|
||||
|
||||
r, err := requests.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthGoogleApiErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthGoogleApiErr, err)
|
||||
}
|
||||
|
||||
gresult := r.Json()
|
||||
|
|
|
@ -46,12 +46,12 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
|
|||
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.ResetToken) // ResetToken
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr, err)
|
||||
}
|
||||
|
||||
// TODO: 存储
|
||||
if rt.OperateType != auth.OpTypeResetToken {
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, "error OperateType: rt.OperateType != auth.OpTypeResetToken")
|
||||
return resp.SetStatus(basic.CodeOAuthTypeErr, fmt.Errorf("error OperateType: rt.OperateType != auth.OpTypeResetToken"))
|
||||
}
|
||||
|
||||
if time.Since(rt.CreateAt) > 30*time.Minute {
|
||||
|
|
|
@ -56,7 +56,7 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
|
|||
resetToken, err := l.svcCtx.ResetTokenManger.Encrypt(token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenEncryptErr, err.Error())
|
||||
return resp.SetStatus(basic.CodeOAuthResetTokenEncryptErr, err)
|
||||
}
|
||||
|
||||
userName := *user.FirstName + " " + *user.LastName
|
||||
|
|
|
@ -41,8 +41,8 @@ func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileRequest, us
|
|||
|
||||
err := l.svcCtx.AllModels.FsUserInfo.MergeMetadata(userinfo.UserId, req)
|
||||
if err != nil {
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) // 返回数据库创建错误
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, err) // 返回数据库创建错误
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
|
|
|
@ -205,22 +205,6 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
if _, ok = mapTagProp[productInfo.Id]; ok {
|
||||
item.CoverDefault = mapTagProp[productInfo.Id]
|
||||
}
|
||||
//千人千面处理
|
||||
/*r := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: 0,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverImg: *productInfo.CoverImg,
|
||||
CoverDefault: *productInfo.CoverImg,
|
||||
ProductId: productInfo.Id,
|
||||
UserId: user.Id,
|
||||
}
|
||||
if user.Id != 0 {
|
||||
r.IsThousandFace = int(*user.IsThousandFace)
|
||||
}
|
||||
image.ThousandFaceImageFormat(&r)
|
||||
item.Cover = r.Cover
|
||||
item.CoverDefault = r.CoverDefault*/
|
||||
//加入分类产品切片
|
||||
listRsp = append(listRsp, item)
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ type wsConnectItem struct {
|
|||
inChan chan []byte //接受消息缓冲队列(基本属性)
|
||||
outChan chan []byte //要发送回客户端的消息缓冲队列(基本属性)
|
||||
mutex sync.Mutex //互斥锁(基本属性)
|
||||
openDebug bool //是否开启debug
|
||||
debug *auth.Debug //是否开启debug
|
||||
userId int64 //用户id(基本属性)
|
||||
guestId int64 //游客id(基本属性)
|
||||
extendRenderProperty extendRenderProperty //扩展云渲染属性(扩展属性)
|
||||
|
@ -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是不是属于自己的用户的
|
||||
|
@ -222,7 +223,13 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
|||
renderCtx: renderCtx,
|
||||
renderCtxCancelFunc: renderCtxCancelFunc,
|
||||
},
|
||||
openDebug: true, //默认都开debug
|
||||
debug: userInfo.Debug,
|
||||
}
|
||||
//先设置下debug(后面要删掉)
|
||||
ws.debug = &auth.Debug{
|
||||
Exp: &userInfo.Exp,
|
||||
IsCache: 1,
|
||||
IsAllTemplateTag: 0,
|
||||
}
|
||||
//保存连接
|
||||
mapConnPool.Store(uniqueId, ws)
|
||||
|
|
|
@ -4,7 +4,7 @@ import "fusenapi/constants"
|
|||
|
||||
// 入口数据格式错误
|
||||
func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) {
|
||||
if !w.openDebug {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, data))
|
||||
|
@ -12,7 +12,7 @@ func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) {
|
|||
|
||||
// 渲染错误通知
|
||||
func (w *wsConnectItem) renderErrResponse(renderId, requestId, templateTag, taskId, description string, productId, userId, guestId, templateId, modelId, sizeId, elementModelId int64) {
|
||||
if !w.openDebug {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
data := make(map[string]interface{})
|
||||
|
|
|
@ -210,7 +210,6 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
logx.Error("failed to get element ,", err)
|
||||
return
|
||||
}
|
||||
|
||||
//获取刀版图
|
||||
combineReq := repositories.LogoCombineReq{
|
||||
UserId: renderImageData.RenderData.UserId,
|
||||
|
@ -229,6 +228,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
Index: renderImageData.RenderData.TemplateTagColor.SelectedColorIndex,
|
||||
},
|
||||
Resolution: renderImageData.RenderData.Resolution,
|
||||
Debug: w.debug,
|
||||
}
|
||||
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
|
||||
if err != nil {
|
||||
|
@ -256,19 +256,24 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
logx.Error("failed to find render resource:", err)
|
||||
return
|
||||
}
|
||||
//无缓存
|
||||
logx.Info("无缓存的渲染图,需要unity")
|
||||
} else {
|
||||
//返回给客户端
|
||||
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderImageData.RenderId,
|
||||
RequestId: renderImageData.RequestId,
|
||||
Image: *resource.ResourceUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
UnityRenderTakesTime: "cache",
|
||||
UploadUnityRenderImageTakesTime: "cache",
|
||||
},
|
||||
})
|
||||
return
|
||||
} else { //有缓存
|
||||
//如果没有debug或者debug模式下开启了缓存则返回缓存
|
||||
if w.debug == nil || w.debug.IsCache == 1 {
|
||||
//返回给客户端
|
||||
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderImageData.RenderId,
|
||||
RequestId: renderImageData.RequestId,
|
||||
Image: *resource.ResourceUrl,
|
||||
RenderProcessTime: websocket_data.RenderProcessTime{
|
||||
UnityRenderTakesTime: "cache",
|
||||
UploadUnityRenderImageTakesTime: "cache",
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
//否则继续去unity
|
||||
}
|
||||
//组装数据
|
||||
if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil {
|
||||
|
@ -463,7 +468,7 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web
|
|||
// ****************************下面的发送消息的*********************************
|
||||
// 发送合图完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId, combineTime, uploadTime int64) {
|
||||
if !w.openDebug {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
combineTakesTime := "cache"
|
||||
|
@ -490,7 +495,7 @@ func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId,
|
|||
|
||||
// 发送组装unity需要的数据完毕消息
|
||||
func (w *wsConnectItem) sendAssembleRenderDataStepResponseMessage(renderId string, requestId string) {
|
||||
if !w.openDebug {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ASSEMBLE_RENDER_DATA, websocket_data.ToUnityRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
|
@ -498,7 +503,7 @@ func (w *wsConnectItem) sendAssembleRenderDataStepResponseMessage(renderId strin
|
|||
|
||||
// 发送组装数据到unity完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendRenderDataToUnityStepResponseMessage(renderId string, requestId string) {
|
||||
if !w.openDebug {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.AssembleRenderDataRspMsg{RenderId: renderId, RequestId: requestId}))
|
||||
|
|
|
@ -131,40 +131,26 @@ func (resp *Response) Set(Code int, Message string) *Response {
|
|||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数, 第二个data就是debug参数
|
||||
func (resp *Response) SetStatus(sr *StatusResponse, dataAndDebug ...interface{}) *Response {
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
if err, ok := data[0].(error); ok {
|
||||
if err, ok := dataAndDebug[0].(error); ok {
|
||||
newResp.Message = err.Error()
|
||||
} else {
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
}
|
||||
case 2:
|
||||
var dataIndex = 0
|
||||
if err, ok := data[dataIndex].(error); ok {
|
||||
newResp.Message = err.Error()
|
||||
dataIndex++
|
||||
} else {
|
||||
panic("data只接收1或2个 data 或 error.Error() 和 data ")
|
||||
}
|
||||
newResp.Data = data[1]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收1或2个 data, error.Error() 和 data ")
|
||||
}
|
||||
|
@ -172,18 +158,80 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon
|
|||
return newResp
|
||||
}
|
||||
|
||||
// SetWithDebug 设置默认StatusResponse(内部自定义) 默认msg, 可以带debug
|
||||
func (resp *Response) SetWithDebug(sr *StatusResponse, debug interface{}) *Response {
|
||||
|
||||
resp = &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message,
|
||||
Debug: debug,
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// WithDebug 设置默认debug参数
|
||||
func (resp *Response) WithDebug(debug interface{}) *Response {
|
||||
|
||||
if resp == nil {
|
||||
panic("must call the func Set... before")
|
||||
}
|
||||
|
||||
resp.Debug = debug
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// WithData 设置默认data参数
|
||||
func (resp *Response) WithData(data interface{}) *Response {
|
||||
|
||||
if resp == nil {
|
||||
panic("must call the func Set... before")
|
||||
}
|
||||
|
||||
resp.Data = data
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// WithMessage 设置默认message参数
|
||||
func (resp *Response) WithMessage(msg string) *Response {
|
||||
|
||||
if resp == nil {
|
||||
panic("must call the func Set... before")
|
||||
}
|
||||
|
||||
resp.Message = msg
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// WithError 设置默认error参数
|
||||
func (resp *Response) WithError(err error) *Response {
|
||||
|
||||
if resp == nil {
|
||||
panic("must call the func Set... before")
|
||||
}
|
||||
|
||||
resp.Message = err.Error()
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data ...interface{}) *Response {
|
||||
func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, dataAndDebug ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: msg,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
case 2:
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收一个 data")
|
||||
}
|
||||
|
@ -191,17 +239,21 @@ func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data
|
|||
return newResp
|
||||
}
|
||||
|
||||
func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data ...interface{}) *Response {
|
||||
// SetStatusAddMessage 这个会拼接默认msg加新的msg
|
||||
func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, dataAndDebug ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message + ":" + msg,
|
||||
}
|
||||
|
||||
switch len(data) {
|
||||
switch len(dataAndDebug) {
|
||||
case 0:
|
||||
// 0 直接返回
|
||||
case 1:
|
||||
newResp.Data = data[0]
|
||||
newResp.Data = dataAndDebug[0]
|
||||
case 2:
|
||||
newResp.Data = dataAndDebug[0]
|
||||
newResp.Debug = dataAndDebug[1]
|
||||
default:
|
||||
panic("data只接收一个 data")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user