From 7c8a8044c95982d32469e3e0fe6e120c93e3af59 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Thu, 23 Nov 2023 14:07:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/file/upload.go | 83 +++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/utils/file/upload.go b/utils/file/upload.go index 55a134c9..c47ca27e 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -90,6 +90,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er // 是否强制刷新 var refresh bool + if req.ResourceId != "" { resourceId = req.ResourceId } @@ -145,34 +146,23 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now().UTC() + var dbData = gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &metadataB, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + } if refresh { - err = tx.Save(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &metadataB, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + err = tx.Save(&dbData).Error } else { - err = tx.Create(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &metadataB, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + err = tx.Create(&dbData).Error } if err != nil { @@ -275,34 +265,23 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro uploadBaseRes.ResourceUrl = url var version string = "0.0.1" var nowTime = time.Now().UTC() + var dbData = gmodel.FsResource{ + ResourceId: resourceId, + UserId: &req.UserId, + GuestId: &req.GuestId, + ResourceType: &contentType, + ResourceUrl: &url, + Version: &version, + UploadedAt: &nowTime, + Metadata: &metadataB, + ApiType: &apiType, + BucketName: bucketName, + Source: &req.Source, + } if refresh { - err = tx.Save(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &metadataB, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + err = tx.Save(&dbData).Error } else { - err = tx.Create(&gmodel.FsResource{ - ResourceId: resourceId, - UserId: &req.UserId, - GuestId: &req.GuestId, - ResourceType: &contentType, - ResourceUrl: &url, - Version: &version, - UploadedAt: &nowTime, - Metadata: &metadataB, - ApiType: &apiType, - BucketName: bucketName, - Source: &req.Source, - }).Error + err = tx.Create(&dbData).Error } if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql")