fix:调整

This commit is contained in:
Hiven 2023-08-08 10:53:28 +08:00
parent dcc3cc4a7d
commit ff86cceb17
4 changed files with 14 additions and 27 deletions

View File

@ -1,7 +1,6 @@
package logic package logic
import ( import (
"fmt"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
@ -47,7 +46,6 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null // userinfo 传入值时, 一定不为null
// 定义用户ID和S3键名格式 // 定义用户ID和S3键名格式
var uid int64
var userId int64 var userId int64
var guestId int64 var guestId int64
@ -55,11 +53,9 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
if userinfo.IsGuest() { if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式 // 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId guestId = userinfo.GuestId
uid = guestId
} else { } else {
// 否则使用用户ID和用户键名格式 // 否则使用用户ID和用户键名格式
userId = userinfo.UserId userId = userinfo.UserId
uid = userId
} }
if guestId == 0 { if guestId == 0 {
guestId = req.GuestId guestId = req.GuestId
@ -89,7 +85,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
// 定义S3请求和当前时间 // 定义S3请求和当前时间
var s3req *request.Request var s3req *request.Request
var resourceId string = hash.JsonHashKey(fmt.Sprintf("%s%d", req.FileKey, uid)) var resourceId string = hash.JsonHashKey(req.FileKey)
var uploadUrl = UploadUrl{} var uploadUrl = UploadUrl{}
resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn)

View File

@ -2,7 +2,6 @@ package logic
import ( import (
"encoding/json" "encoding/json"
"fmt"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
@ -57,7 +56,6 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
} }
// 定义用户ID和S3键名格式 // 定义用户ID和S3键名格式
var uid int64
var userId int64 var userId int64
var guestId int64 var guestId int64
@ -65,11 +63,9 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
if userinfo.IsGuest() { if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式 // 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId guestId = userinfo.GuestId
uid = guestId
} else { } else {
// 否则使用用户ID和用户键名格式 // 否则使用用户ID和用户键名格式
userId = userinfo.UserId userId = userinfo.UserId
uid = userId
} }
var uploadInfoList []UploadInfo var uploadInfoList []UploadInfo
@ -132,7 +128,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
// 一系列业务逻辑....验证类型,文件大小 // 一系列业务逻辑....验证类型,文件大小
var hashKey string = hash.JsonHashKey(fmt.Sprintf("%s%d", info.FileKeys, uid)) var hashKey string = hash.JsonHashKey(info.FileKeys)
source <- UploadData{ source <- UploadData{
FileKey: info.FileKeys, FileKey: info.FileKeys,
FileType: fileType, FileType: fileType,

View File

@ -2,7 +2,6 @@ package logic
import ( import (
"encoding/json" "encoding/json"
"fmt"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"fusenapi/utils/hash" "fusenapi/utils/hash"
@ -45,21 +44,6 @@ func NewUploadFilesFrontendLogic(ctx context.Context, svcCtx *svc.ServiceContext
func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null // userinfo 传入值时, 一定不为null
// 定义用户ID和S3键名格式
var uid int64
var userId int64
var guestId int64
// 检查用户是否是游客
if userinfo.IsGuest() {
// 如果是使用游客ID和游客键名格式
guestId = userinfo.GuestId
uid = guestId
} else {
// 否则使用用户ID和用户键名格式
userId = userinfo.UserId
uid = userId
}
var uploadInfoList []UploadInfo var uploadInfoList []UploadInfo
err := json.Unmarshal([]byte(req.UploadInfo), &uploadInfoList) err := json.Unmarshal([]byte(req.UploadInfo), &uploadInfoList)
@ -98,7 +82,7 @@ func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq
for _, info := range uploadInfoList { for _, info := range uploadInfoList {
if info.FileSize <= 1024*1024*500 { if info.FileSize <= 1024*1024*500 {
// 一系列业务逻辑....验证类型,文件大小 // 一系列业务逻辑....验证类型,文件大小
var hashKey string = hash.JsonHashKey(fmt.Sprintf("%s%d", info.FileKeys, uid)) var hashKey string = hash.JsonHashKey(info.FileKeys)
source <- UploadData{ source <- UploadData{
FileKey: info.FileKeys, FileKey: info.FileKeys,
FileSize: info.FileSize, FileSize: info.FileSize,

View File

@ -5,10 +5,21 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
"fmt" "fmt"
"reflect"
"sort" "sort"
) )
func JsonHashKey(v interface{}) string { func JsonHashKey(v interface{}) string {
if reflect.TypeOf(v).Kind() == reflect.String {
var obj interface{}
err := json.Unmarshal([]byte(v.(string)), &obj)
if err == nil {
// 反序列化成功,直接替换v
v = obj
}
}
h := sha256.New() h := sha256.New()
h.Write(marshalOrdered(v)) h.Write(marshalOrdered(v))
return fmt.Sprintf("%x", h.Sum(nil)) return fmt.Sprintf("%x", h.Sum(nil))