fix:修复上传

This commit is contained in:
Hiven 2023-08-10 16:13:06 +08:00
parent a2ee8327ac
commit 74cadf6e5b

View File

@ -67,8 +67,8 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
var uploadBaseRes = UploadBaseRes{}
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
resourceModelTS := gmodel.NewFsResourceModel(tx)
resourceInfo, err := resourceModelTS.FindOneById(upload.Ctx, resourceId)
var resourceInfo *gmodel.FsResource
err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
if err == nil && resourceInfo.ResourceId != "" {
uploadBaseRes.Status = 1
uploadBaseRes.ResourceId = resourceId
@ -108,7 +108,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
uploadBaseRes.ResourceUrl = url
var version string = "0.0.1"
var nowTime = time.Now()
_, err = resourceModelTS.Create(upload.Ctx, &gmodel.FsResource{
err = tx.Create(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
@ -119,7 +119,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
})
}).Error
if err != nil {
logx.Errorf("err:%+vdesc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
return err
@ -163,10 +163,11 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
var resourceId string = req.FileHash
var uploadBaseRes = UploadBaseRes{}
ctx := upload.Ctx
err := upload.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
resourceModelTS := gmodel.NewFsResourceModel(connGorm)
resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId)
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
var resourceInfo *gmodel.FsResource
err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
// resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId)
if err == nil && resourceInfo.ResourceId != "" {
uploadBaseRes.Status = 1
uploadBaseRes.ResourceId = resourceId
@ -200,7 +201,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
uploadBaseRes.ResourceUrl = url
var version string = "0.0.1"
var nowTime = time.Now()
_, err = resourceModelTS.Create(ctx, &gmodel.FsResource{
err = tx.Create(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
@ -211,7 +212,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
})
}).Error
if err != nil {
logx.Errorf("err:%+vdesc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
return err