fix:修复上传
This commit is contained in:
parent
a2ee8327ac
commit
74cadf6e5b
|
@ -67,8 +67,8 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
|
|
||||||
var uploadBaseRes = UploadBaseRes{}
|
var uploadBaseRes = UploadBaseRes{}
|
||||||
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
resourceModelTS := gmodel.NewFsResourceModel(tx)
|
var resourceInfo *gmodel.FsResource
|
||||||
resourceInfo, err := resourceModelTS.FindOneById(upload.Ctx, resourceId)
|
err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
|
||||||
if err == nil && resourceInfo.ResourceId != "" {
|
if err == nil && resourceInfo.ResourceId != "" {
|
||||||
uploadBaseRes.Status = 1
|
uploadBaseRes.Status = 1
|
||||||
uploadBaseRes.ResourceId = resourceId
|
uploadBaseRes.ResourceId = resourceId
|
||||||
|
@ -108,7 +108,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
uploadBaseRes.ResourceUrl = url
|
uploadBaseRes.ResourceUrl = url
|
||||||
var version string = "0.0.1"
|
var version string = "0.0.1"
|
||||||
var nowTime = time.Now()
|
var nowTime = time.Now()
|
||||||
_, err = resourceModelTS.Create(upload.Ctx, &gmodel.FsResource{
|
err = tx.Create(&gmodel.FsResource{
|
||||||
ResourceId: resourceId,
|
ResourceId: resourceId,
|
||||||
UserId: &req.UserId,
|
UserId: &req.UserId,
|
||||||
GuestId: &req.GuestId,
|
GuestId: &req.GuestId,
|
||||||
|
@ -119,7 +119,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
|
||||||
Metadata: &req.Metadata,
|
Metadata: &req.Metadata,
|
||||||
ApiType: &apiType,
|
ApiType: &apiType,
|
||||||
BucketName: bucketName,
|
BucketName: bucketName,
|
||||||
})
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
|
logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
|
||||||
return err
|
return err
|
||||||
|
@ -163,10 +163,11 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
|
||||||
var resourceId string = req.FileHash
|
var resourceId string = req.FileHash
|
||||||
|
|
||||||
var uploadBaseRes = UploadBaseRes{}
|
var uploadBaseRes = UploadBaseRes{}
|
||||||
ctx := upload.Ctx
|
|
||||||
err := upload.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
|
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
resourceModelTS := gmodel.NewFsResourceModel(connGorm)
|
var resourceInfo *gmodel.FsResource
|
||||||
resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId)
|
err := tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
|
||||||
|
// resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId)
|
||||||
if err == nil && resourceInfo.ResourceId != "" {
|
if err == nil && resourceInfo.ResourceId != "" {
|
||||||
uploadBaseRes.Status = 1
|
uploadBaseRes.Status = 1
|
||||||
uploadBaseRes.ResourceId = resourceId
|
uploadBaseRes.ResourceId = resourceId
|
||||||
|
@ -200,7 +201,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
|
||||||
uploadBaseRes.ResourceUrl = url
|
uploadBaseRes.ResourceUrl = url
|
||||||
var version string = "0.0.1"
|
var version string = "0.0.1"
|
||||||
var nowTime = time.Now()
|
var nowTime = time.Now()
|
||||||
_, err = resourceModelTS.Create(ctx, &gmodel.FsResource{
|
err = tx.Create(&gmodel.FsResource{
|
||||||
ResourceId: resourceId,
|
ResourceId: resourceId,
|
||||||
UserId: &req.UserId,
|
UserId: &req.UserId,
|
||||||
GuestId: &req.GuestId,
|
GuestId: &req.GuestId,
|
||||||
|
@ -211,7 +212,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
|
||||||
Metadata: &req.Metadata,
|
Metadata: &req.Metadata,
|
||||||
ApiType: &apiType,
|
ApiType: &apiType,
|
||||||
BucketName: bucketName,
|
BucketName: bucketName,
|
||||||
})
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
|
logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user