diff --git a/server/upload/etc/upload.yaml b/server/upload/etc/upload.yaml index 12b42062..a2a2cb4b 100644 --- a/server/upload/etc/upload.yaml +++ b/server/upload/etc/upload.yaml @@ -1,7 +1,7 @@ Name: upload Host: 0.0.0.0 Port: 9912 -Timeout: 15000 #服务超时时间 +Timeout: 150000 #服务超时时间 SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Env: "test" Auth: diff --git a/server/upload/internal/handler/routes.go b/server/upload/internal/handler/routes.go index e33dc5a8..03536a1d 100644 --- a/server/upload/internal/handler/routes.go +++ b/server/upload/internal/handler/routes.go @@ -57,6 +57,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/upload/upload-file-base", Handler: UploadFileBaseHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/upload/up-standard-logo", + Handler: UploadLogoStandardHandler(serverCtx), + }, }, ) } diff --git a/server/upload/internal/handler/uploadlogostandardhandler.go b/server/upload/internal/handler/uploadlogostandardhandler.go new file mode 100644 index 00000000..813f1978 --- /dev/null +++ b/server/upload/internal/handler/uploadlogostandardhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/upload/internal/logic" + "fusenapi/server/upload/internal/svc" + "fusenapi/server/upload/internal/types" +) + +func UploadLogoStandardHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UploadLogoStandardReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUploadLogoStandardLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UploadLogoStandard(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index 0019177a..bd495c61 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -152,29 +152,29 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us 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.Second*20) + result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5) if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") + 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") + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 02") } if string(b) == "Internal Server Error" { err = errors.New("BLMService fail Internal Server Error") logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") + 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") + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 04") } if resData != nil { @@ -182,11 +182,11 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us resultStr = resData["data"].(string) } else { logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail") + return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail 05") } } else { logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 06") } } diff --git a/server/upload/internal/logic/uploadlogostandardlogic.go b/server/upload/internal/logic/uploadlogostandardlogic.go new file mode 100644 index 00000000..7f2c3a30 --- /dev/null +++ b/server/upload/internal/logic/uploadlogostandardlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/upload/internal/svc" + "fusenapi/server/upload/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UploadLogoStandardLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUploadLogoStandardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoStandardLogic { + return &UploadLogoStandardLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UploadLogoStandardLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UploadLogoStandardLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *UploadLogoStandardLogic) UploadLogoStandard(req *types.UploadLogoStandardReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index 4a946586..8aa84e78 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -5,6 +5,14 @@ import ( "fusenapi/utils/basic" ) +type UploadLogoStandardReq 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 UploadFileBaseReq struct { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 FileKey string `form:"file_key"` // 上传唯一标识信息 diff --git a/server_api/upload.api b/server_api/upload.api index 85e85433..7aaa9ec0 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -42,8 +42,21 @@ service upload { @handler UploadFileBaseHandler post /api/upload/upload-file-base(UploadFileBaseReq) returns (response); + @handler UploadLogoStandardHandler + post /api/upload/up-standard-logo(UploadLogoStandardReq) returns (response); + } +type ( + UploadLogoStandardReq { + IsRemoveBg string `form:"is_remove_bg"` + LogoFile string `form:"logo_file"` + Width string `form:"width"` + Height string `form:"height"` + Proportion int64 `form:"proportion"` + } +) + type ( UploadFileBaseReq { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 6ff54137..b68c3c98 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -37,6 +37,9 @@ type ( // logo合图 LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) + + // logo裁剪 + LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) } ) @@ -225,3 +228,20 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } /* logo合图 */ +type ( + LogoStandardReq struct { + IsRemoveBg string `json:"is_remove_bg"` + LogoFile string `json:"logo_file"` + Width string `json:"width"` + Height string `json:"height"` + Proportion int64 `json:"proportion"` + } + LogoStandardRes struct{} +) + +/* 图片裁剪 */ +func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { + return nil, nil +} + +/* 图片裁剪 */