fix:重构合图模块
This commit is contained in:
parent
318f92b869
commit
69f08415fc
|
@ -2,6 +2,7 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
@ -69,11 +70,29 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||||
//设置内存大小
|
//设置内存大小
|
||||||
l.r.ParseMultipartForm(32 << 20)
|
l.r.ParseMultipartForm(32 << 20)
|
||||||
|
|
||||||
fileObject, _, err := l.r.FormFile("file")
|
fileObject, fileHeader, err := l.r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")
|
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")
|
||||||
}
|
}
|
||||||
|
defer fileObject.Close()
|
||||||
|
|
||||||
|
// 获取文件的MIME类型
|
||||||
|
fileType := fileHeader.Header.Get("Content-Type")
|
||||||
|
var imageTypes = make(map[string]struct{}, 7)
|
||||||
|
imageTypes["image/jpg"] = struct{}{}
|
||||||
|
imageTypes["image/jpeg"] = struct{}{}
|
||||||
|
imageTypes["image/png"] = struct{}{}
|
||||||
|
imageTypes["image/gif"] = struct{}{}
|
||||||
|
imageTypes["image/bmp"] = struct{}{}
|
||||||
|
imageTypes["image/tiff"] = struct{}{}
|
||||||
|
imageTypes["image/webp"] = struct{}{}
|
||||||
|
imageTypes["image/svg+xml"] = struct{}{}
|
||||||
|
// 判断文件类型是否为图片
|
||||||
|
_, ok := imageTypes[fileType]
|
||||||
|
if !ok {
|
||||||
|
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,file is not image")
|
||||||
|
}
|
||||||
|
|
||||||
// 读取数据流
|
// 读取数据流
|
||||||
ioData, err := io.ReadAll(fileObject)
|
ioData, err := io.ReadAll(fileObject)
|
||||||
|
@ -143,10 +162,30 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
|
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
|
||||||
}
|
}
|
||||||
resultStr = string(b)
|
|
||||||
|
|
||||||
if resultStr == "Internal Server Error" {
|
if string(b) == "Internal Server Error" {
|
||||||
return resp.SetStatus(basic.CodeFileUploadLogoErr, resultStr)
|
err = errors.New("BLMService fail Internal Server Error")
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
|
||||||
|
} 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
if resData != nil {
|
||||||
|
if resData["code"].(string) == "200" {
|
||||||
|
resultStr = resData["data"].(string)
|
||||||
|
} else {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var module = "logo"
|
var module = "logo"
|
||||||
|
|
|
@ -165,17 +165,35 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ress := string(b)
|
var resultStr string
|
||||||
|
if string(b) == "Internal Server Error" {
|
||||||
if ress == "Internal Server Error" {
|
|
||||||
err = errors.New("BLMService fail Internal Server Error")
|
err = errors.New("BLMService fail Internal Server Error")
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else {
|
||||||
|
var resData map[string]interface{}
|
||||||
|
err = json.Unmarshal(b, &resData)
|
||||||
|
if err != nil || resData == nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resData != nil {
|
||||||
|
if resData["code"].(string) == "200" {
|
||||||
|
resultStr = resData["data"].(string)
|
||||||
|
} else {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultData map[string]interface{}
|
var resultData map[string]interface{}
|
||||||
err = json.Unmarshal(b, &resultData)
|
err = json.Unmarshal([]byte(resultStr), &resultData)
|
||||||
if err != nil {
|
if err != nil || resultData == nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,10 @@ var (
|
||||||
CodeAesCbcEncryptionErr = &StatusResponse{5106, "encryption data err"} // 加密数据失败
|
CodeAesCbcEncryptionErr = &StatusResponse{5106, "encryption data err"} // 加密数据失败
|
||||||
CodeAesCbcDecryptionErr = &StatusResponse{5107, "decryption data err"} // 解密数据失败
|
CodeAesCbcDecryptionErr = &StatusResponse{5107, "decryption data err"} // 解密数据失败
|
||||||
|
|
||||||
CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败
|
CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败
|
||||||
CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败
|
CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败
|
||||||
CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败
|
CodeFileUploadLogoErrType = &StatusResponse{5111, "logo upload err file is not image"} // 用户上位LOGO失败"}
|
||||||
|
CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user