Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into feature/auth
This commit is contained in:
@@ -9,12 +9,10 @@ import (
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/render/internal/svc"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/hash"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 这里请求的py接口返回数据
|
||||
@@ -51,8 +49,18 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
rabbitmq := initalize.RabbitMqHandle{}
|
||||
//根据templateTag获取templateTagId(后续模板表的tag改成template_tag后可能就不需要这个步骤了)
|
||||
templateTag, err := svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(ctx, parseInfo.RenderData.TemplateTag)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("can`t find template tag info by template tag:", parseInfo.RenderData.TemplateTag)
|
||||
return nil
|
||||
}
|
||||
logx.Error("failed to get template tag info")
|
||||
return nil
|
||||
}
|
||||
//获取模板(模板标签下的对一个物料的的模板)
|
||||
productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId))
|
||||
productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", templateTag.Id))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("template info is not found")
|
||||
@@ -61,33 +69,17 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
||||
logx.Error("failed to get template info:", err)
|
||||
return nil //不返回错误就删除消息
|
||||
}
|
||||
time.Now().UTC()
|
||||
resourceKey := hash.JsonHashKey(parseInfo)
|
||||
combineParam := map[string]interface{}{
|
||||
"logo_url": parseInfo.RenderData.Logo,
|
||||
"website": "",
|
||||
"slogan": "",
|
||||
"address": "",
|
||||
"phone": "",
|
||||
"colors": []string{},
|
||||
"template_tagid": "b1a",
|
||||
"is_crop": false,
|
||||
"shape": "rectangle",
|
||||
"ratio": 0,
|
||||
"line": "",
|
||||
"other": "",
|
||||
"other1": "",
|
||||
}
|
||||
combineParamBytes, _ := json.Marshal(combineParam)
|
||||
//获取刀版图
|
||||
res, err := svcCtx.Repositories.ImageHandle.LogoCombine(ctx, &repositories.LogoCombineReq{
|
||||
ResourceKey: resourceKey,
|
||||
TemplateId: productTemplate.Id,
|
||||
CombineParam: string(combineParamBytes),
|
||||
UserId: parseInfo.RenderData.UserId,
|
||||
GuestId: parseInfo.RenderData.GuestId,
|
||||
UserId: parseInfo.RenderData.UserId,
|
||||
GuestId: parseInfo.RenderData.GuestId,
|
||||
TemplateId: productTemplate.Id,
|
||||
TemplateTag: parseInfo.RenderData.TemplateTag,
|
||||
Website: parseInfo.RenderData.Website,
|
||||
Slogan: parseInfo.RenderData.Slogan,
|
||||
Address: parseInfo.RenderData.Address,
|
||||
Phone: parseInfo.RenderData.Phone,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logx.Error("合成刀版图失败:", err)
|
||||
return nil
|
||||
@@ -99,7 +91,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
||||
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
|
||||
return nil
|
||||
}
|
||||
logx.Info("合成刀版图成功")
|
||||
logx.Info("合成刀版图成功:", *res.ResourceUrl)
|
||||
//获取渲染设置信息
|
||||
element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *productTemplate.ModelId)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
Name: render
|
||||
Host: 0.0.0.0
|
||||
Port: 9919
|
||||
<<<<<<< HEAD
|
||||
ReplicaId: 55
|
||||
=======
|
||||
Timeout: 15000 #服务超时时间
|
||||
>>>>>>> ac1800bb26ce44fba8be8271c7be2b8403c7d7f5
|
||||
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
|
||||
@@ -39,30 +39,15 @@ func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Rend
|
||||
// }
|
||||
|
||||
func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
/*if time.Now().Unix()-120 > req.Time || req.Time > time.Now().Unix() {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time")
|
||||
}*/
|
||||
if req.Info.TaskId == "" {
|
||||
if req.TaskId == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id")
|
||||
}
|
||||
if req.Info.Image == "" {
|
||||
if req.Image == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
|
||||
}
|
||||
if req.Info.UserId == 0 && req.Info.GuestId == 0 {
|
||||
if req.UserId == 0 && req.GuestId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid user_id or guest_id")
|
||||
}
|
||||
/* if req.Sign == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param sign")
|
||||
}*/
|
||||
//验证签名 sha256
|
||||
/*notifyByte, _ := json.Marshal(req.Info)
|
||||
h := sha256.New()
|
||||
h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time)))
|
||||
signHex := h.Sum(nil)
|
||||
sign := hex.EncodeToString(signHex)
|
||||
if req.Sign != sign {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign")
|
||||
}*/
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
Ctx: l.ctx,
|
||||
@@ -70,12 +55,12 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
}
|
||||
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
|
||||
FileHash: req.Info.TaskId,
|
||||
FileData: req.Info.Image,
|
||||
FileHash: req.TaskId,
|
||||
FileData: req.Image,
|
||||
UploadBucket: 1,
|
||||
ApiType: 2,
|
||||
UserId: req.Info.UserId,
|
||||
GuestId: req.Info.GuestId,
|
||||
UserId: req.UserId,
|
||||
GuestId: req.GuestId,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
@@ -83,13 +68,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
||||
}
|
||||
//发送消息到对应的rabbitmq
|
||||
data := websocket_data.RenderImageNotify{
|
||||
TaskId: req.Info.TaskId,
|
||||
TaskId: req.TaskId,
|
||||
Image: uploadRes.ResourceUrl,
|
||||
}
|
||||
d, _ := json.Marshal(data)
|
||||
if err = l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeServiceErr, "failed to send data")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to send data")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
||||
|
||||
@@ -12,12 +12,6 @@ type RequestReadImages struct {
|
||||
}
|
||||
|
||||
type RenderNotifyReq struct {
|
||||
Sign string `json:"sign"`
|
||||
Time int64 `json:"time"`
|
||||
Info NotifyInfo `json:"info"`
|
||||
}
|
||||
|
||||
type NotifyInfo struct {
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
UserId int64 `json:"user_id"`
|
||||
GuestId int64 `json:"guest_id"`
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/render/consumer"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
|
||||
@@ -26,7 +25,6 @@ func main() {
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
c.Timeout = int64(time.Second * 15)
|
||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||
}))
|
||||
defer server.Stop()
|
||||
|
||||
Reference in New Issue
Block a user