fusenapi/server/data-transfer/internal/logic/uploadlogologic.go
laodaming fdcd8c46e0 fix
2023-06-12 20:05:51 +08:00

59 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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