生命周期的指令上传
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/check"
|
||||
"fusenapi/utils/format"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"fusenapi/server/upload/internal/types"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -55,26 +57,61 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.RequestUploadFileB
|
||||
return resp.SetStatus(basic.CodeS3CategoryErr)
|
||||
}
|
||||
|
||||
var s3req *request.Request
|
||||
now := time.Now()
|
||||
s3req, _ := svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: aws.String("storage.fusenpack.com"),
|
||||
Key: aws.String(format.FormatS3KeyName(
|
||||
keytype,
|
||||
uid,
|
||||
now,
|
||||
l.svcCtx.Config.Env,
|
||||
req.Category,
|
||||
req.File.Filename,
|
||||
)),
|
||||
},
|
||||
)
|
||||
category := format.TypeCategory(req.Category)
|
||||
ObjectKey := aws.String(format.FormatS3KeyName(
|
||||
keytype,
|
||||
uid,
|
||||
now,
|
||||
l.svcCtx.Config.Env,
|
||||
category,
|
||||
req.File.Filename,
|
||||
))
|
||||
|
||||
switch category {
|
||||
case format.TCategoryRenderMegre:
|
||||
|
||||
lifecycleConfiguration := &s3.BucketLifecycleConfiguration{
|
||||
Rules: []*s3.LifecycleRule{
|
||||
{
|
||||
Status: aws.String("Enabled"),
|
||||
// Status: aws.String("Disabled"),
|
||||
Filter: &s3.LifecycleRuleFilter{
|
||||
Prefix: ObjectKey,
|
||||
},
|
||||
Expiration: &s3.LifecycleExpiration{
|
||||
// Date: aws.Time(time.Now().UTC().Add(time.Minute)),
|
||||
Days: aws.Int64(1), // 设置过期天数,例如:30天
|
||||
},
|
||||
// ID: aws.String("ExpireAfter01Days"), // 设置规则的唯一标识符
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
s3req, _ = svc.PutBucketLifecycleConfigurationRequest(
|
||||
&s3.PutBucketLifecycleConfigurationInput{
|
||||
Bucket: basic.StorageBucketName,
|
||||
LifecycleConfiguration: lifecycleConfiguration,
|
||||
},
|
||||
)
|
||||
default:
|
||||
s3req, _ = svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: basic.StorageBucketName,
|
||||
Key: ObjectKey,
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
s3req.SetBufferBody(req.File.Data)
|
||||
err := s3req.Send()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeS3PutObjectRequestErr)
|
||||
}
|
||||
log.Println(s3req.HTTPRequest.URL)
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"upload_url": s3req.HTTPRequest.URL.String(),
|
||||
|
||||
@@ -61,6 +61,7 @@ func (l *UploadFileFrontendLogic) UploadFileFrontend(req *types.RequestUploadFil
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
s3req, _ := svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: aws.String("storage.fusenpack.com"),
|
||||
@@ -69,7 +70,7 @@ func (l *UploadFileFrontendLogic) UploadFileFrontend(req *types.RequestUploadFil
|
||||
uid,
|
||||
now,
|
||||
l.svcCtx.Config.Env,
|
||||
req.Category,
|
||||
format.TypeCategory(req.Category),
|
||||
req.FileName,
|
||||
)),
|
||||
ContentLength: aws.Int64(req.FileSize),
|
||||
|
||||
Reference in New Issue
Block a user