上传完善

This commit is contained in:
Hiven 2023-08-02 11:30:27 +08:00
parent d75bc8f2be
commit 3388b446fd
4 changed files with 29 additions and 29 deletions

View File

@ -144,17 +144,20 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
}
}
}, func(item interface{}, writer mr.Writer[interface{}], cancel func(error)) {
var uploadUrl = UploadUrl{}
uploadDataInfo := item.(UploadData)
var uploadUrl = UploadUrl{}
uploadUrl.Key = uploadDataInfo.FileKey
uploadUrl.ApiType = uploadDataInfo.ApiType
uploadUrl.ResourceType = uploadDataInfo.FileType
var resourceId string = uploadDataInfo.HashKey
// 查询数据库
resourceInfo, err := resourceModel.FindOneById(l.ctx, resourceId)
if err == nil && resourceInfo.ResourceId != "" {
uploadUrl.Status = 1
uploadUrl.ResourceId = resourceId
uploadUrl.Url = *resourceInfo.ResourceUrl
uploadUrl.Key = uploadDataInfo.FileKey
uploadUrl.ResourceUrl = *resourceInfo.ResourceUrl
} else {
// 创建S3对象存储请求
s3req, _ = svc.PutObjectRequest(
@ -169,21 +172,17 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
// 发送请求
err = s3req.Send()
// 检查是否有错误
if err != nil {
logx.Error(err)
uploadUrl.Status = 0
uploadUrl.Url = ""
uploadUrl.Key = uploadDataInfo.FileKey
} else {
var url = s3req.HTTPRequest.URL.String()
// 打印请求URL
logx.Info(url)
uploadUrl.Status = 1
uploadUrl.Url = url
uploadUrl.Key = uploadDataInfo.FileKey
uploadUrl.ResourceId = resourceId
uploadUrl.ResourceUrl = url
var version string = "0.0.1"
var nowTime = time.Now()
_, err = resourceModel.CreateOrUpdate(l.ctx, &gmodel.FsResource{
@ -251,9 +250,10 @@ type UploadData struct {
}
type UploadUrl struct {
Status int64 `json:"status"`
ResourceId string `json:"resource_id"`
Url string `json:"url"`
Key string `json:"key"`
Metadata string `json:"metadata"`
Key string `json:"key"`
Status int64 `json:"status"`
ApiType int64 `json:"api_type"`
ResourceId string `json:"resource_id"`
ResourceType string `json:"resource_type"`
ResourceUrl string `json:"resource_url"`
}

View File

@ -108,9 +108,13 @@ func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq
}
}
}, func(item interface{}, writer mr.Writer[interface{}], cancel func(error)) {
var uploadUrl = UploadUrl{}
uploadDataInfo := item.(UploadData)
var uploadUrl = UploadUrl{}
uploadUrl.Key = uploadDataInfo.FileKey
uploadUrl.ApiType = uploadDataInfo.ApiType
uploadUrl.ResourceType = uploadDataInfo.FileType
s3req, _ := svc.PutObjectRequest(
&s3.PutObjectInput{
Bucket: uploadDataInfo.Bucket,
@ -123,16 +127,12 @@ func (l *UploadFilesFrontendLogic) UploadFilesFrontend(req *types.UploadFilesReq
if err != nil {
logx.Error(err)
uploadUrl.Status = 0
uploadUrl.Url = ""
uploadUrl.ResourceId = uploadDataInfo.HashKey
uploadUrl.Key = uploadDataInfo.FileKey
} else {
// 打印请求URL
logx.Info(url)
uploadUrl.Status = 1
uploadUrl.Url = url
uploadUrl.ResourceUrl = url
uploadUrl.ResourceId = uploadDataInfo.HashKey
uploadUrl.Key = uploadDataInfo.FileKey
}
// Notice 这个必须加!
writer.Write(uploadUrl)

View File

@ -18,11 +18,11 @@ type UploadFilesReq struct {
}
type UploadCallbackReq struct {
FileType string `form:"file_type"` // 文件类型 / fbx / hdr
UploadKey string `form:"upload_key"` // 上传KEY
UploadBucket string `form:"upload_bucket"` // 上传桶名
Version string `form:"version,optional"` // 版本信息
Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率
ResourceId string `form:"resource_id"` // 资源ID
ResourceType string `form:"resource_type"` // 资源类型
ResourceUrl string `form:"resource_url"` // 资源URL
Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型1=对外2=对内
}
type RequestUpFile struct {

View File

@ -48,11 +48,11 @@ type (
UploadInfo string `form:"upload_info"` // 上传信息 json
}
UploadCallbackReq {
FileType string `form:"file_type"` // 文件类型 / fbx / hdr
UploadKey string `form:"upload_key"` // 上传KEY
UploadBucket string `form:"upload_bucket"` // 上传桶名
Version string `form:"version,optional"` // 版本信息
Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率
ResourceId string `form:"resource_id"` // 资源ID
ResourceType string `form:"resource_type"` // 资源类型
ResourceUrl string `form:"resource_url"` // 资源URL
Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型1=对外2=对内
}
)