diff --git a/server/upload/internal/logic/uploadfilebaselogic.go b/server/upload/internal/logic/uploadfilebaselogic.go index 55326ac1..c0562483 100644 --- a/server/upload/internal/logic/uploadfilebaselogic.go +++ b/server/upload/internal/logic/uploadfilebaselogic.go @@ -78,6 +78,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri UserId: userId, GuestId: guestId, Source: req.Source, + Refresh: req.Refresh, }) if err != nil { diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index 5d38ea5a..ef9f9a62 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -22,7 +22,7 @@ type UploadFileBaseReq struct { GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 Source string `form:"source"` // 上传来源 - Refresh bool `form:"refresh,optional"` // 强制更新 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 } type UploadLogoReq struct { diff --git a/server_api/upload.api b/server_api/upload.api index 47d17443..3b847250 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -67,7 +67,7 @@ type ( GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 Source string `form:"source"` // 上传来源 - Refresh bool `form:"refresh,optional"` // 强制更新 + Refresh int64 `form:"refresh,optional"` // 强制更新 10 } ) diff --git a/utils/file/upload.go b/utils/file/upload.go index 04fe7c69..937579e7 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -22,7 +22,7 @@ type Upload struct { } type UploadBaseReq struct { - Refresh bool + Refresh int64 Source string FileHash string FileData string @@ -71,11 +71,11 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource - if !req.Refresh { + if req.Refresh == 0 { err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error } - if !req.Refresh && err == nil && resourceInfo.ResourceId != "" { + if req.Refresh == 0 && err == nil && resourceInfo.ResourceId != "" { uploadBaseRes.Status = 1 uploadBaseRes.ResourceId = resourceId uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl @@ -114,19 +114,36 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now().UTC() - err = tx.Create(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &req.Metadata, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + if req.Refresh == 1 { + err = tx.Save(&gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &req.Metadata, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + }).Error + } else { + err = tx.Create(&gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &req.Metadata, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + }).Error + } + if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") return err