fix(infra): GetObjectUrl Expire unset (#2104)

main
Ryo 1 month ago committed by GitHub
parent 9a0b45eccf
commit 1d9fa80972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      backend/infra/impl/storage/internal/fileutil/file_util.go
  2. 12
      backend/infra/impl/storage/s3/s3.go
  3. 12
      backend/infra/impl/storage/tos/tos.go

@ -30,7 +30,7 @@ func AssembleFileUrl(ctx context.Context, urlExpire *int64, files []*storage.Fil
taskGroup := taskgroup.NewTaskGroup(ctx, 5) taskGroup := taskgroup.NewTaskGroup(ctx, 5)
for idx := range files { for idx := range files {
f := files[idx] f := files[idx]
expire := int64(60 * 60 * 24) expire := int64(7 * 60 * 60 * 24)
if urlExpire != nil && *urlExpire > 0 { if urlExpire != nil && *urlExpire > 0 {
expire = *urlExpire expire = *urlExpire
} }

@ -229,11 +229,21 @@ func (t *s3Client) GetObjectUrl(ctx context.Context, objectKey string, opts ...s
bucket := t.bucketName bucket := t.bucketName
presignClient := s3.NewPresignClient(client) presignClient := s3.NewPresignClient(client)
opt := storage.GetOption{}
for _, optFn := range opts {
optFn(&opt)
}
expire := int64(60 * 60 * 24)
if opt.Expire > 0 {
expire = opt.Expire
}
req, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{ req, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(objectKey), Key: aws.String(objectKey),
}, func(options *s3.PresignOptions) { }, func(options *s3.PresignOptions) {
options.Expires = time.Duration(60*60*24) * time.Second options.Expires = time.Duration(expire) * time.Second
}) })
if err != nil { if err != nil {
return "", fmt.Errorf("get object presigned url failed: %v", err) return "", fmt.Errorf("get object presigned url failed: %v", err)

@ -246,9 +246,19 @@ func (t *tosClient) GetObjectUrl(ctx context.Context, objectKey string, opts ...
client := t.client client := t.client
bucketName := t.bucketName bucketName := t.bucketName
opt := storage.GetOption{}
for _, optFn := range opts {
optFn(&opt)
}
expire := int64(7 * 24 * 60 * 60)
if opt.Expire > 0 {
expire = opt.Expire
}
output, err := client.PreSignedURL(&tos.PreSignedURLInput{ output, err := client.PreSignedURL(&tos.PreSignedURLInput{
HTTPMethod: enum.HttpMethodGet, HTTPMethod: enum.HttpMethodGet,
Expires: 60 * 60 * 24, Expires: expire,
Bucket: bucketName, Bucket: bucketName,
Key: objectKey, Key: objectKey,
}) })

Loading…
Cancel
Save