diff --git a/backend/infra/impl/storage/internal/fileutil/file_util.go b/backend/infra/impl/storage/internal/fileutil/file_util.go index e6e72b2e..e9654af5 100644 --- a/backend/infra/impl/storage/internal/fileutil/file_util.go +++ b/backend/infra/impl/storage/internal/fileutil/file_util.go @@ -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 } diff --git a/backend/infra/impl/storage/s3/s3.go b/backend/infra/impl/storage/s3/s3.go index ea8b6fd8..9b25af20 100644 --- a/backend/infra/impl/storage/s3/s3.go +++ b/backend/infra/impl/storage/s3/s3.go @@ -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) diff --git a/backend/infra/impl/storage/tos/tos.go b/backend/infra/impl/storage/tos/tos.go index 0ca9d18c..cff8d732 100644 --- a/backend/infra/impl/storage/tos/tos.go +++ b/backend/infra/impl/storage/tos/tos.go @@ -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, })