package s3 import ( "context" "io" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/s3" stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types" ) type DirReader struct { cli *s3.Client bucket string rootPath jcstypes.JPath marker *string curInfos []stgtypes.DirEntry eof bool } func (r *DirReader) Next() (stgtypes.DirEntry, error) { if len(r.curInfos) > 0 { e := r.curInfos[0] r.curInfos = r.curInfos[1:] return e, nil } if r.eof { return stgtypes.DirEntry{}, io.EOF } resp, err := r.cli.ListObjects(context.Background(), &s3.ListObjectsInput{ Bucket: aws.String(r.bucket), Prefix: aws.String(r.rootPath.String()), Marker: r.marker, }) if err != nil { return stgtypes.DirEntry{}, err } for _, obj := range resp.Contents { key := jcstypes.PathFromJcsPathString(*obj.Key) r.curInfos = append(r.curInfos, stgtypes.DirEntry{ Path: key, Size: *obj.Size, ModTime: *obj.LastModified, IsDir: false, }) } if !*resp.IsTruncated { r.eof = true } r.marker = resp.NextMarker return r.Next() } func (r *DirReader) Close() { }