From 47401c49bddf43852a6104c949773aa57bacb15e Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 23 Aug 2023 15:44:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A3=81=E5=89=AA=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/file/upload.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) 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,