feat(infra): add file listing support (#1836)

This commit is contained in:
Ryo
2025-08-27 12:06:55 +08:00
committed by GitHub
parent 901d0252e8
commit 263a75b1c0
8 changed files with 512 additions and 141 deletions

View File

@@ -19,6 +19,7 @@ package storage
import (
"context"
"io"
"time"
)
//go:generate mockgen -destination ../../../internal/mock/infra/contract/storage/storage_mock.go -package mock -source storage.go Factory
@@ -28,6 +29,13 @@ type Storage interface {
GetObject(ctx context.Context, objectKey string) ([]byte, error)
DeleteObject(ctx context.Context, objectKey string) error
GetObjectUrl(ctx context.Context, objectKey string, opts ...GetOptFn) (string, error)
// ListObjects returns all objects with the specified prefix.
// It may return a large number of objects, consider using ListObjectsPaginated for better performance.
ListObjects(ctx context.Context, prefix string) ([]*FileInfo, error)
// ListObjectsPaginated returns objects with pagination support.
// Use this method when dealing with large number of objects.
ListObjectsPaginated(ctx context.Context, input *ListObjectsPaginatedInput) (*ListObjectsPaginatedOutput, error)
}
type SecurityToken struct {
@@ -37,3 +45,23 @@ type SecurityToken struct {
ExpiredTime string `thrift:"expired_time,4" frugal:"4,default,string" json:"expired_time"`
CurrentTime string `thrift:"current_time,5" frugal:"5,default,string" json:"current_time"`
}
type ListObjectsPaginatedInput struct {
Prefix string
PageSize int
Cursor string
}
type ListObjectsPaginatedOutput struct {
Files []*FileInfo
Cursor string
// false: All results have been returned
// true: There are more results to return
IsTruncated bool
}
type FileInfo struct {
Key string
LastModified time.Time
ETag string
Size int64
}