diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index 8aa84e78..4d077417 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -22,6 +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"` // 强制更新 } type UploadLogoReq struct { diff --git a/server_api/upload.api b/server_api/upload.api index 7aaa9ec0..c4af90f2 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -67,6 +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"` // 强制更新 } ) diff --git a/utils/file/upload.go b/utils/file/upload.go index d561ae28..e50c0070 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -22,6 +22,7 @@ type Upload struct { } type UploadBaseReq struct { + Refresh bool Source string FileHash string FileData string @@ -67,10 +68,14 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er var resourceId string = req.FileHash var uploadBaseRes = UploadBaseRes{} - err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error { + err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource - err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error - if err == nil && resourceInfo.ResourceId != "" { + + if !req.Refresh { + err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error + } + + if !req.Refresh && err == nil && resourceInfo.ResourceId != "" { uploadBaseRes.Status = 1 uploadBaseRes.ResourceId = resourceId uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl