Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-08-23 18:16:19 +08:00
commit 6babc1c5cd
4 changed files with 65 additions and 23 deletions

View File

@ -91,6 +91,9 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendR
UserId: userId,
GuestId: guestId,
Source: req.Source,
Metadata: req.Metadata,
Refresh: req.Refresh,
ResourceId: req.ResourceId,
})
if err != nil {

View File

@ -40,6 +40,8 @@ type UploadFileBackendReq struct {
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
Source string `form:"source"` // 上传来源
Refresh int64 `form:"refresh,optional"` // 强制更新 10
ResourceId string `form:"resource_id,optional"` // 资源ID
}
type UploadFilesReq struct {
@ -47,6 +49,8 @@ type UploadFilesReq struct {
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
UploadInfo string `form:"upload_info"` // 上传信息 json
Source string `form:"source"` // 上传来源
Refresh int64 `form:"refresh,optional"` // 强制更新 10
ResourceId string `form:"resource_id,optional"` // 资源ID
}
type UploadCallbackReq struct {

View File

@ -89,6 +89,8 @@ type (
FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
Source string `form:"source"` // 上传来源
Refresh int64 `form:"refresh,optional"` // 强制更新 10
ResourceId string `form:"resource_id,optional"` // 资源ID
}
UploadFilesReq {
@ -96,6 +98,8 @@ type (
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久
UploadInfo string `form:"upload_info"` // 上传信息 json
Source string `form:"source"` // 上传来源
Refresh int64 `form:"refresh,optional"` // 强制更新 10
ResourceId string `form:"resource_id,optional"` // 资源ID
}
UploadCallbackReq {
UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久

View File

@ -70,12 +70,14 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
var uploadBaseRes = UploadBaseRes{}
// 是否强制刷新
var refresh bool
if req.ResourceId != "" {
refresh = true
resourceId = req.ResourceId
}
if req.Refresh == 1 {
refresh = true
}
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err error) {
var resourceInfo *gmodel.FsResource
@ -198,15 +200,28 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
var uploadBaseRes = UploadBaseRes{}
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) error {
// 是否强制刷新
var refresh bool
if req.ResourceId != "" {
resourceId = req.ResourceId
}
if req.Refresh == 1 {
refresh = true
}
err := upload.MysqlConn.Transaction(func(tx *gorm.DB) (err 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
uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl
} else {
if !refresh {
err = tx.Where("resource_id =?", resourceId).Take(&resourceInfo).Error
if err == nil && resourceInfo.ResourceId != "" {
uploadBaseRes.Status = 1
uploadBaseRes.ResourceId = resourceId
uploadBaseRes.ResourceUrl = *resourceInfo.ResourceUrl
} else {
refresh = true
}
}
if refresh {
contentType := http.DetectContentType(req.FileByte)
// 创建S3对象存储请求
s3req, _ = svc.PutObjectRequest(
@ -235,19 +250,35 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
uploadBaseRes.ResourceUrl = url
var version string = "0.0.1"
var nowTime = time.Now().UTC()
err = tx.Create(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
ResourceType: &contentType,
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
}).Error
if refresh {
err = tx.Save(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
ResourceType: &contentType,
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
}).Error
} else {
err = tx.Create(&gmodel.FsResource{
ResourceId: resourceId,
UserId: &req.UserId,
GuestId: &req.GuestId,
ResourceType: &contentType,
ResourceUrl: &url,
Version: &version,
UploadedAt: &nowTime,
Metadata: &req.Metadata,
ApiType: &apiType,
BucketName: bucketName,
Source: &req.Source,
}).Error
}
if err != nil {
logx.Errorf("err:%+vdesc:%+v", err, "fail.upload.resourceInfoAdd.mysql")
return err