fix
This commit is contained in:
parent
6e41658b7d
commit
69e2fd4362
|
@ -27,11 +27,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/upload/qrcode",
|
Path: "/upload/qrcode",
|
||||||
Handler: UploadQrcodeHandler(serverCtx),
|
Handler: UploadQrcodeHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/upload/up-logo",
|
|
||||||
Handler: UploadLogoHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/data-transfer/internal/logic"
|
|
||||||
"fusenapi/server/data-transfer/internal/svc"
|
|
||||||
"fusenapi/server/data-transfer/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// 解析jwtToken
|
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从Token里获取对应的信息
|
|
||||||
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req types.UploadLogoReq
|
|
||||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 510,
|
|
||||||
Message: "parameter error",
|
|
||||||
})
|
|
||||||
logx.Info(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewUploadLogoLogic(r.Context(), svcCtx)
|
|
||||||
resp := l.UploadLogo(&req, userinfo, r)
|
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
|
||||||
if resp != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
} else {
|
|
||||||
err := errors.New("server logic is error, resp must not be nil")
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
logx.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"fusenapi/utils/image"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"fusenapi/server/data-transfer/internal/svc"
|
|
||||||
"fusenapi/server/data-transfer/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UploadLogoLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoLogic {
|
|
||||||
return &UploadLogoLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, loginInfo *auth.UserInfo, r *http.Request) (resp *basic.Response) {
|
|
||||||
req.LogoFile = strings.Trim(req.LogoFile, " ")
|
|
||||||
//图片是否做缩放[php代码不是bool是字符串??然后给python处理]
|
|
||||||
onlyScale := "false"
|
|
||||||
imageUrl := ""
|
|
||||||
if req.LogoFile != "" {
|
|
||||||
onlyScale = "true"
|
|
||||||
imageUrl = req.LogoFile
|
|
||||||
} else {
|
|
||||||
file, fileInfo, err := r.FormFile("upfile")
|
|
||||||
if err != nil {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
if !image.CheckUploadImageFormat(fileInfo.Filename) {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, "format of the file is invalid ")
|
|
||||||
}
|
|
||||||
fileData, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
|
||||||
}
|
|
||||||
_ = os.WriteFile("a.jpeg", fileData, 0666)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
|
@ -26,20 +26,6 @@ type UploadQrcodeRsp struct {
|
||||||
Data string `json:"d"`
|
Data string `json:"d"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadLogoReq struct {
|
|
||||||
LogoFile string `form:"logo_file"` //logo地址路径
|
|
||||||
SkuId int64 `form:"skuId"`
|
|
||||||
IsRemoveBg bool `form:"is_remove_bg"`
|
|
||||||
Proportion int64 `form:"proportion"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UploadLogoRsp struct {
|
|
||||||
NobgUrl string `json:"nobg_url"`
|
|
||||||
ThumbnailUrl string `json:"thumbnail_url"`
|
|
||||||
IsmaxProportion bool `json:"ismax_proportion"`
|
|
||||||
ImgColor []string `json:"img_color"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
|
|
@ -19,9 +19,6 @@ service data-transfer {
|
||||||
//生成二维码
|
//生成二维码
|
||||||
@handler UploadQrcodeHandler
|
@handler UploadQrcodeHandler
|
||||||
post /upload/qrcode (UploadQrcodeReq) returns (response);
|
post /upload/qrcode (UploadQrcodeReq) returns (response);
|
||||||
//上传logo
|
|
||||||
@handler UploadLogoHandler
|
|
||||||
post /upload/up-logo (UploadLogoReq) returns (response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取标准logo列表
|
//获取标准logo列表
|
||||||
|
@ -44,17 +41,3 @@ type UploadQrcodeRsp {
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Data string `json:"d"`
|
Data string `json:"d"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//上传logo
|
|
||||||
type UploadLogoReq {
|
|
||||||
LogoFile string `form:"logo_file"` //logo地址路径
|
|
||||||
SkuId int64 `form:"skuId"`
|
|
||||||
IsRemoveBg bool `form:"is_remove_bg"`
|
|
||||||
Proportion int64 `form:"proportion"`
|
|
||||||
}
|
|
||||||
type UploadLogoRsp {
|
|
||||||
NobgUrl string `json:"nobg_url"`
|
|
||||||
ThumbnailUrl string `json:"thumbnail_url"`
|
|
||||||
IsmaxProportion bool `json:"ismax_proportion"`
|
|
||||||
ImgColor []string `json:"img_color"`
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user