Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
ccaca2ae07
35
server/resource/internal/handler/logoremovebghandler.go
Normal file
35
server/resource/internal/handler/logoremovebghandler.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/resource/internal/logic"
|
||||||
|
"fusenapi/server/resource/internal/svc"
|
||||||
|
"fusenapi/server/resource/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LogoRemovebgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.LogoRemovebgReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewLogoRemovebgLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.LogoRemovebg(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/resource/logo-combine",
|
Path: "/api/resource/logo-combine",
|
||||||
Handler: LogoCombineHandler(serverCtx),
|
Handler: LogoCombineHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/resource/logo-removebg",
|
||||||
|
Handler: LogoRemovebgHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/resource/info",
|
Path: "/api/resource/info",
|
||||||
|
|
61
server/resource/internal/logic/logoremovebglogic.go
Normal file
61
server/resource/internal/logic/logoremovebglogic.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/service/repositories"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/resource/internal/svc"
|
||||||
|
"fusenapi/server/resource/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogoRemovebgLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLogoRemovebgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoRemovebgLogic {
|
||||||
|
return &LogoRemovebgLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *LogoRemovebgLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *LogoRemovebgLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *LogoRemovebgLogic) LogoRemovebg(req *types.LogoRemovebgReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
res, err := l.svcCtx.Repositories.ImageHandle.LogoStandard(l.ctx, &repositories.LogoStandardReq{
|
||||||
|
IsRemoveBg: req.IsRemoveBg,
|
||||||
|
LogoFile: req.LogoFile,
|
||||||
|
Width: req.Width,
|
||||||
|
Height: req.Height,
|
||||||
|
Proportion: req.Proportion,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功的响应和上传URL
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
|
"resource_id": res.ResourceId,
|
||||||
|
"resource_url": res.ResourceUrl,
|
||||||
|
"ismax_proportion": res.IsmaxProportion,
|
||||||
|
"img_color": req.Proportion,
|
||||||
|
})
|
||||||
|
}
|
|
@ -5,6 +5,14 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type LogoRemovebgReq struct {
|
||||||
|
IsRemoveBg string `form:"is_remove_bg"`
|
||||||
|
LogoFile string `form:"logo_file"`
|
||||||
|
Width string `form:"width"`
|
||||||
|
Height string `form:"height"`
|
||||||
|
Proportion int64 `form:"proportion"`
|
||||||
|
}
|
||||||
|
|
||||||
type ResourceInfoReq struct {
|
type ResourceInfoReq struct {
|
||||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
ResourceKey string `form:"resource_key,optional"` // 资源唯一标识
|
ResourceKey string `form:"resource_key,optional"` // 资源唯一标识
|
||||||
|
|
|
@ -13,10 +13,23 @@ service resource {
|
||||||
@handler LogoCombineHandler
|
@handler LogoCombineHandler
|
||||||
post /api/resource/logo-combine(LogoCombineReq) returns (response);
|
post /api/resource/logo-combine(LogoCombineReq) returns (response);
|
||||||
|
|
||||||
|
@handler LogoRemovebgHandler
|
||||||
|
post /api/resource/logo-removebg(LogoRemovebgReq) returns (response);
|
||||||
|
|
||||||
@handler ResourceInfoHandler
|
@handler ResourceInfoHandler
|
||||||
get /api/resource/info(ResourceInfoReq) returns (response);
|
get /api/resource/info(ResourceInfoReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
LogoRemovebgReq {
|
||||||
|
IsRemoveBg string `form:"is_remove_bg"`
|
||||||
|
LogoFile string `form:"logo_file"`
|
||||||
|
Width string `form:"width"`
|
||||||
|
Height string `form:"height"`
|
||||||
|
Proportion int64 `form:"proportion"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
ResourceInfoReq {
|
ResourceInfoReq {
|
||||||
ResourceId string `form:"resource_id,optional"` // 资源ID
|
ResourceId string `form:"resource_id,optional"` // 资源ID
|
||||||
|
|
|
@ -250,7 +250,8 @@ type (
|
||||||
|
|
||||||
/* 图片裁剪 */
|
/* 图片裁剪 */
|
||||||
func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) {
|
func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) {
|
||||||
var postMap = make(map[string]interface{}, 2)
|
var resourceId string = hash.JsonHashKey(in)
|
||||||
|
var postMap = make(map[string]interface{}, 5)
|
||||||
postMap["is_remove_bg"] = in.IsRemoveBg
|
postMap["is_remove_bg"] = in.IsRemoveBg
|
||||||
postMap["logo_file"] = in.LogoFile
|
postMap["logo_file"] = in.LogoFile
|
||||||
postMap["width"] = in.Width
|
postMap["width"] = in.Width
|
||||||
|
@ -305,7 +306,37 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
|
||||||
}
|
}
|
||||||
//$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}'
|
//$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}'
|
||||||
|
|
||||||
return nil, nil
|
var fileBase = resultData["nobg_url"].(string)
|
||||||
|
var ismaxProportion = resultData["ismax_proportion"].(bool)
|
||||||
|
|
||||||
|
var imgColor []string
|
||||||
|
for _, v := range resultData["img_color"].([]interface{}) {
|
||||||
|
imgColor = append(imgColor, v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
var upload = file.Upload{
|
||||||
|
Ctx: ctx,
|
||||||
|
MysqlConn: l.MysqlConn,
|
||||||
|
AwsSession: l.AwsSession,
|
||||||
|
}
|
||||||
|
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
|
||||||
|
Source: "combine-removebg",
|
||||||
|
FileHash: resourceId,
|
||||||
|
FileData: fileBase,
|
||||||
|
UploadBucket: 1,
|
||||||
|
ApiType: 2,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &LogoStandardRes{
|
||||||
|
ResourceId: uploadRes.ResourceId,
|
||||||
|
ResourceUrl: uploadRes.ResourceUrl,
|
||||||
|
IsmaxProportion: ismaxProportion,
|
||||||
|
ImgColor: imgColor,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 图片裁剪 */
|
/* 图片裁剪 */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user