Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-08-18 16:58:36 +08:00
commit 1bde6e5d53
8 changed files with 132 additions and 8 deletions

View File

@ -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:

View File

@ -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),
},
},
)
}

View File

@ -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)
}
}
}

View File

@ -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")
}
}

View File

@ -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)
}

View File

@ -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"` // 上传唯一标识信息

View File

@ -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=对内

View File

@ -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
}
/* 图片裁剪 */