2023-06-12 02:15:40 +00:00
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2023-06-12 09:00:37 +00:00
|
|
|
|
"fusenapi/utils/auth"
|
2023-06-12 02:16:49 +00:00
|
|
|
|
"fusenapi/utils/basic"
|
2023-06-12 12:05:51 +00:00
|
|
|
|
"fusenapi/utils/image"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
2023-06-12 02:15:40 +00:00
|
|
|
|
|
|
|
|
|
"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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 12:05:51 +00:00
|
|
|
|
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)
|
|
|
|
|
}
|
2023-06-12 02:15:40 +00:00
|
|
|
|
|
|
|
|
|
return resp.SetStatus(basic.CodeOK)
|
|
|
|
|
}
|