fix(infra): GetObjectUrl Expire unset (#2104)
This commit is contained in:
@ -30,7 +30,7 @@ func AssembleFileUrl(ctx context.Context, urlExpire *int64, files []*storage.Fil
|
||||
taskGroup := taskgroup.NewTaskGroup(ctx, 5)
|
||||
for idx := range files {
|
||||
f := files[idx]
|
||||
expire := int64(60 * 60 * 24)
|
||||
expire := int64(7 * 60 * 60 * 24)
|
||||
if urlExpire != nil && *urlExpire > 0 {
|
||||
expire = *urlExpire
|
||||
}
|
||||
|
||||
@ -229,11 +229,21 @@ func (t *s3Client) GetObjectUrl(ctx context.Context, objectKey string, opts ...s
|
||||
bucket := t.bucketName
|
||||
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{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(objectKey),
|
||||
}, func(options *s3.PresignOptions) {
|
||||
options.Expires = time.Duration(60*60*24) * time.Second
|
||||
options.Expires = time.Duration(expire) * time.Second
|
||||
})
|
||||
if err != nil {
|
||||
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
|
||||
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{
|
||||
HTTPMethod: enum.HttpMethodGet,
|
||||
Expires: 60 * 60 * 24,
|
||||
Expires: expire,
|
||||
Bucket: bucketName,
|
||||
Key: objectKey,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user