fix:裁剪业务逻辑调整
This commit is contained in:
@@ -35,6 +35,8 @@ type (
|
||||
}
|
||||
|
||||
ImageHandle = interface {
|
||||
// logo信息
|
||||
LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error)
|
||||
|
||||
// logo合图
|
||||
LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error)
|
||||
@@ -44,6 +46,32 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
/* logo信息 */
|
||||
type (
|
||||
LogoInfoSetReq struct {
|
||||
LogoUrl string `json:"logo_url"`
|
||||
}
|
||||
LogoInfoSetRes struct{}
|
||||
)
|
||||
|
||||
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
|
||||
var resultBLM constants.BLMServiceUrlResult
|
||||
postMap := make(map[string]string, 1)
|
||||
postMap["logo_url"] = in.LogoUrl
|
||||
|
||||
_, err := curl.NewClient(ctx, &curl.Config{
|
||||
BaseUrl: *l.BLMServiceUrl,
|
||||
Url: constants.BLMServiceUrlLogoCombine,
|
||||
}).PostForm(postMap, &resultBLM)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
/* logo信息 */
|
||||
|
||||
/* logo合图 */
|
||||
type (
|
||||
LogoCombineReq struct {
|
||||
@@ -249,7 +277,7 @@ type (
|
||||
LogoFile string `json:"logo_file"`
|
||||
Width string `json:"width"`
|
||||
Height string `json:"height"`
|
||||
Proportion int64 `json:"proportion"`
|
||||
Proportion string `json:"proportion"`
|
||||
}
|
||||
LogoStandardRes struct {
|
||||
ResourceId string
|
||||
@@ -299,53 +327,24 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
|
||||
}
|
||||
}
|
||||
|
||||
var resultBLM constants.BLMServiceUrlResult
|
||||
var postMap = make(map[string]interface{}, 5)
|
||||
postMap["is_remove_bg"] = in.IsRemoveBg
|
||||
postMap["logo_file"] = in.LogoFile
|
||||
postMap["width"] = in.Width
|
||||
postMap["height"] = in.Height
|
||||
postMap["proportion"] = in.Proportion
|
||||
postMapB, _ := json.Marshal(postMap)
|
||||
|
||||
var headerData = make(map[string]string, 1)
|
||||
headerData["Content-Type"] = "application/json"
|
||||
result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoRemovebg, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5)
|
||||
err = curl.NewClient(ctx, &curl.Config{
|
||||
BaseUrl: *l.BLMServiceUrl,
|
||||
Url: constants.BLMServiceUrlLogoRemovebg,
|
||||
}).PostJson(postMap, &resultBLM)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
defer result.Body.Close()
|
||||
b, err := io.ReadAll(result.Body)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
var resultStr string
|
||||
if string(b) == "Internal Server Error" {
|
||||
err = errors.New("BLMService fail Internal Server Error")
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
} else {
|
||||
var resData map[string]interface{}
|
||||
err = json.Unmarshal(b, &resData)
|
||||
if err != nil || resData == nil {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resData != nil {
|
||||
if resData["code"].(string) == "200" {
|
||||
resultStr = resData["data"].(string)
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var resultStr string = resultBLM.Data.(string)
|
||||
var resultData map[string]interface{}
|
||||
err = json.Unmarshal([]byte(resultStr), &resultData)
|
||||
if err != nil || resultData == nil {
|
||||
@@ -353,8 +352,6 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}'
|
||||
|
||||
var fileBase = resultData["nobg_url"].(string)
|
||||
ismaxProportion = resultData["ismax_proportion"].(bool)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user