Skip to content

Commit e0344d6

Browse files
committed
fix(infra): GetObjectUrl Expire unset
1 parent 9a0b45e commit e0344d6

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

backend/infra/impl/storage/internal/fileutil/file_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func AssembleFileUrl(ctx context.Context, urlExpire *int64, files []*storage.Fil
3030
taskGroup := taskgroup.NewTaskGroup(ctx, 5)
3131
for idx := range files {
3232
f := files[idx]
33-
expire := int64(60 * 60 * 24)
33+
expire := int64(7 * 60 * 60 * 24)
3434
if urlExpire != nil && *urlExpire > 0 {
3535
expire = *urlExpire
3636
}

backend/infra/impl/storage/s3/s3.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,21 @@ func (t *s3Client) GetObjectUrl(ctx context.Context, objectKey string, opts ...s
229229
bucket := t.bucketName
230230
presignClient := s3.NewPresignClient(client)
231231

232+
opt := storage.GetOption{}
233+
for _, optFn := range opts {
234+
optFn(&opt)
235+
}
236+
237+
expire := int64(60 * 60 * 24)
238+
if opt.Expire > 0 {
239+
expire = opt.Expire
240+
}
241+
232242
req, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
233243
Bucket: aws.String(bucket),
234244
Key: aws.String(objectKey),
235245
}, func(options *s3.PresignOptions) {
236-
options.Expires = time.Duration(60*60*24) * time.Second
246+
options.Expires = time.Duration(expire) * time.Second
237247
})
238248
if err != nil {
239249
return "", fmt.Errorf("get object presigned url failed: %v", err)

backend/infra/impl/storage/tos/tos.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,19 @@ func (t *tosClient) GetObjectUrl(ctx context.Context, objectKey string, opts ...
246246
client := t.client
247247
bucketName := t.bucketName
248248

249+
opt := storage.GetOption{}
250+
for _, optFn := range opts {
251+
optFn(&opt)
252+
}
253+
254+
expire := int64(7 * 24 * 60 * 60)
255+
if opt.Expire > 0 {
256+
expire = opt.Expire
257+
}
258+
249259
output, err := client.PreSignedURL(&tos.PreSignedURLInput{
250260
HTTPMethod: enum.HttpMethodGet,
251-
Expires: 60 * 60 * 24,
261+
Expires: expire,
252262
Bucket: bucketName,
253263
Key: objectKey,
254264
})

0 commit comments

Comments
 (0)