diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4118472..d15f941 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -14,6 +14,10 @@ jobs: - uses: dart-lang/setup-dart@v1 - name: Install dependencies run: dart pub get + - name: Add version + env: + TAG_VERSION: ${{ github.event.release.tag_name }} + run: echo "\n\nversion: ${TAG_VERSION##v}" >> pubspec.yaml - name: Check Publish Warnings run: dart pub publish --dry-run - name: Publish diff --git a/example/pubspec.yaml b/example/pubspec.yaml index e4c7868..d554b2a 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -7,8 +7,7 @@ environment: sdk: ^3.2.5 dependencies: - nitric_sdk: - path: ../ + nitric_sdk: ^1.0.0 uuid: ^4.3.3 dev_dependencies: diff --git a/lib/src/api/bucket.dart b/lib/src/api/bucket.dart index 3d785c2..6863022 100644 --- a/lib/src/api/bucket.dart +++ b/lib/src/api/bucket.dart @@ -30,6 +30,16 @@ class Bucket { return File(this, key); } + /// Get a list of references to the files in the bucket. Optionally supply a [prefix] to filter by. + Future> files({String prefix = ""}) async { + final request = + $p.StorageListBlobsRequest(bucketName: name, prefix: prefix); + + var resp = await _storageClient.listBlobs(request); + + return resp.blobs.map((blob) => File(this, blob.key)).toList(); + } + /// Create a blob event subscription triggered on the [blobEventType] filtered by files that match the [keyPrefixFilter]. Future on(BlobEventType blobEventType, String keyPrefixFilter, BlobEventHandler handler) async { diff --git a/pubspec.yaml b/pubspec.yaml index 9912bd7..4c50527 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,5 @@ name: nitric_sdk description: A Dart SDK for creating Nitric applications -version: 1.0.0 repository: https://github.com/nitrictech/dart_sdk environment: diff --git a/test/src/api/bucket_test.dart b/test/src/api/bucket_test.dart index a0093c6..25e0074 100644 --- a/test/src/api/bucket_test.dart +++ b/test/src/api/bucket_test.dart @@ -32,6 +32,49 @@ void main() { expect(file.key, "fileName"); }); + test('Test get list of files with no prefix filter', () async { + var req = StorageListBlobsRequest(bucketName: "bucketName", prefix: ""); + + var resp = StorageListBlobsResponse( + blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]); + + when(() => storageClient.listBlobs(req)) + .thenAnswer((_) => MockResponseFuture.value(resp)); + + var bucket = Bucket("bucketName", client: storageClient); + + var blobs = await bucket.files(); + + verify(() => storageClient.listBlobs(req)).called(1); + + expect(blobs.length, 3); + expect(blobs[0].key, "blob-a"); + expect(blobs[1].key, "blob-b"); + expect(blobs[2].key, "blob-c"); + }); + + test('Test get list of files with prefix filter', () async { + var req = + StorageListBlobsRequest(bucketName: "bucketName", prefix: "blob-"); + + var resp = StorageListBlobsResponse( + blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]); + + when(() => storageClient.listBlobs(req)) + .thenAnswer((_) => MockResponseFuture.value(resp)); + + var bucket = Bucket("bucketName", client: storageClient); + + var blobs = await bucket.files(prefix: "blob-"); + + verify(() => storageClient.listBlobs(req)).called(1); + + expect(blobs.length, 3); + expect(blobs[0].key, "blob-a"); + expect(blobs[1].key, "blob-b"); + expect(blobs[2].key, "blob-c"); + }); + test('Test write to file', () async { var req = StorageWriteRequest( bucketName: "bucketName",