diff --git a/utils/file/upload.go b/utils/file/upload.go index ec956b10..89b84a44 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -70,27 +70,26 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er var uploadBaseRes = UploadBaseRes{} - // var refresh bool + var refresh bool - // if req.ResourceId != "" { - // refresh = true - // } + if req.ResourceId != "" { + refresh = true + resourceId = req.ResourceId + } err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) { var resourceInfo *gmodel.FsResource - if req.ResourceId == "" { + if !refresh { err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error - } - - if req.ResourceId == "" && err == nil && resourceInfo.ResourceId != "" { - uploadBaseRes.Status = 1 - uploadBaseRes.ResourceId = resourceId - uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl - } else { - if req.ResourceId != "" { - resourceId = req.ResourceId + if err == nil && resourceInfo.ResourceId != "" { + uploadBaseRes.Status = 1 + uploadBaseRes.ResourceId = resourceId + uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl + } else { + refresh = true } - + } + if refresh { dist, contentType, err := FileBase64ToByte(req.FileData) if err != nil { @@ -125,7 +124,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now().UTC() - if req.Refresh == 1 { + if refresh { err = tx.Save(&gmodel.FsResource{ ResourceId: resourceId, UserId: &req.UserId,