Feat v0.8.0 files module (#67)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m45s
CI/CD / test-sqlite (push) Successful in 2m52s
CI/CD / build-and-deploy (push) Successful in 1m20s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m45s
CI/CD / test-sqlite (push) Successful in 2m52s
CI/CD / build-and-deploy (push) Successful in 1m20s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #67.
This commit is contained in:
@@ -232,6 +232,49 @@ func (s *S3Store) Exists(ctx context.Context, key string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// List returns objects under the given prefix, up to limit entries.
|
||||
func (s *S3Store) List(ctx context.Context, prefix string, limit int) ([]ObjectEntry, error) {
|
||||
if prefix != "" {
|
||||
if err := validateKey(prefix); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
}
|
||||
|
||||
fullPrefix := s.fullKey(prefix)
|
||||
objectsCh := s.client.ListObjects(ctx, s.bucket, minio.ListObjectsOptions{
|
||||
Prefix: fullPrefix,
|
||||
Recursive: true,
|
||||
})
|
||||
|
||||
var entries []ObjectEntry
|
||||
for obj := range objectsCh {
|
||||
if obj.Err != nil {
|
||||
return entries, fmt.Errorf("storage/s3: list %q: %w", prefix, obj.Err)
|
||||
}
|
||||
if len(entries) >= limit {
|
||||
// Drain the remaining channel entries (minio requires it).
|
||||
for range objectsCh {
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Strip the s3 prefix to recover the storage key.
|
||||
key := strings.TrimPrefix(obj.Key, s.prefix)
|
||||
|
||||
ct := obj.ContentType
|
||||
if ct == "" {
|
||||
ct = "application/octet-stream"
|
||||
}
|
||||
|
||||
entries = append(entries, ObjectEntry{Key: key, Size: obj.Size, ContentType: ct})
|
||||
}
|
||||
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
// Healthy checks connectivity by performing a HeadBucket.
|
||||
func (s *S3Store) Healthy(ctx context.Context) error {
|
||||
exists, err := s.client.BucketExists(ctx, s.bucket)
|
||||
|
||||
Reference in New Issue
Block a user