59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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)
|
||
}
|