fix:调整
This commit is contained in:
parent
dcc3cc4a7d
commit
ff86cceb17
|
@ -1,7 +1,6 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
@ -47,7 +46,6 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
// 定义用户ID和S3键名格式
|
||||
var uid int64
|
||||
var userId int64
|
||||
var guestId int64
|
||||
|
||||
|
@ -55,11 +53,9 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
uid = guestId
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
userId = userinfo.UserId
|
||||
uid = userId
|
||||
}
|
||||
if guestId == 0 {
|
||||
guestId = req.GuestId
|
||||
|
@ -89,7 +85,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
// 定义S3请求和当前时间
|
||||
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{}
|
||||
resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn)
|
||||
|
|
|
@ -2,7 +2,6 @@ package logic
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
@ -57,7 +56,6 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
|
|||
}
|
||||
|
||||
// 定义用户ID和S3键名格式
|
||||
var uid int64
|
||||
var userId int64
|
||||
var guestId int64
|
||||
|
||||
|
@ -65,11 +63,9 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
|
|||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
uid = guestId
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
userId = userinfo.UserId
|
||||
uid = userId
|
||||
}
|
||||
|
||||
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{
|
||||
FileKey: info.FileKeys,
|
||||
FileType: fileType,
|
||||
|
|
|
@ -2,7 +2,6 @@ package logic
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"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) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// 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
|
||||
err := json.Unmarshal([]byte(req.UploadInfo), &uploadInfoList)
|
||||
|
@ -98,7 +82,7 @@ func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq
|
|||
for _, info := range uploadInfoList {
|
||||
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{
|
||||
FileKey: info.FileKeys,
|
||||
FileSize: info.FileSize,
|
||||
|
|
|
@ -5,10 +5,21 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
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.Write(marshalOrdered(v))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
|
Loading…
Reference in New Issue
Block a user