fix:裁剪业务逻辑调整
This commit is contained in:
@@ -80,6 +80,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
||||
Source: req.Source,
|
||||
Refresh: req.Refresh,
|
||||
Metadata: req.Metadata,
|
||||
ResourceId: req.ResourceId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/curl"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/hash"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
@@ -126,13 +122,25 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
Source: "upload-logo",
|
||||
})
|
||||
|
||||
var logoUrl string
|
||||
|
||||
// 是否去背景
|
||||
if req.IsRemoveBg == 1 {
|
||||
// res, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{})
|
||||
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoStandard(l.ctx, &repositories.LogoStandardReq{
|
||||
LogoFile: uploadRes.ResourceUrl,
|
||||
IsRemoveBg: "true",
|
||||
Width: "0",
|
||||
Height: "0",
|
||||
Proportion: "100",
|
||||
})
|
||||
logoUrl = resLogoStandard.ResourceUrl
|
||||
|
||||
// if err != nil {
|
||||
// return resp.SetStatus(basic.CodeServiceErr)
|
||||
// }
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
} else {
|
||||
logoUrl = uploadRes.ResourceUrl
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -140,8 +148,6 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
||||
}
|
||||
|
||||
logx.Infof("上传logo请求算法--开始时间:%v", time.Now())
|
||||
|
||||
var logoWidth int64
|
||||
var logoHeight int64
|
||||
// 查看sku是否存在
|
||||
@@ -165,52 +171,17 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
var resultStr string
|
||||
|
||||
var postMap = make(map[string]string, 1)
|
||||
postMap["logo_url"] = uploadRes.ResourceUrl
|
||||
postMapB, _ := json.Marshal(postMap)
|
||||
fmt.Println(string(postMapB))
|
||||
postMap["logo_url"] = logoUrl
|
||||
|
||||
var headerData = make(map[string]string, 1)
|
||||
headerData["Content-Type"] = "application/json"
|
||||
result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
||||
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{
|
||||
LogoUrl: logoUrl,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 01")
|
||||
}
|
||||
defer result.Body.Close()
|
||||
b, err := io.ReadAll(result.Body)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 02")
|
||||
}
|
||||
|
||||
logx.Infof("上传logo请求算法--结束时间:%v", time.Now())
|
||||
logx.Infof("上传logo请求算法--返回结果:%v", string(b))
|
||||
|
||||
if string(b) == "Internal Server Error" {
|
||||
err = errors.New("BLMService fail Internal Server Error")
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 03")
|
||||
} else {
|
||||
var resData map[string]interface{}
|
||||
err = json.Unmarshal(b, &resData)
|
||||
if err != nil || resData == nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 04")
|
||||
}
|
||||
|
||||
if resData != nil {
|
||||
if resData["code"].(string) == "200" {
|
||||
resultStr = resData["data"].(string)
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail 05")
|
||||
}
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 06")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
resultStr = resLogoStandard.Res
|
||||
|
||||
var module = "logo"
|
||||
var nowTime = time.Now().Unix()
|
||||
|
||||
@@ -23,6 +23,7 @@ type UploadFileBaseReq struct {
|
||||
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
|
||||
Source string `form:"source"` // 上传来源
|
||||
Refresh int64 `form:"refresh,optional"` // 强制更新 10
|
||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||
}
|
||||
|
||||
type UploadLogoReq struct {
|
||||
|
||||
Reference in New Issue
Block a user