Skip to content

Commit c89325e

Browse files
feat: add ability to list files in bucket and fix release workflow (#20)
* feat: add ability to list blobs in bucket * ci: update release workflow to add version tag
1 parent bdf2be4 commit c89325e

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

.github/workflows/publish.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
- uses: dart-lang/setup-dart@v1
1515
- name: Install dependencies
1616
run: dart pub get
17+
- name: Add version
18+
env:
19+
TAG_VERSION: ${{ github.event.release.tag_name }}
20+
run: echo "\n\nversion: ${TAG_VERSION##v}" >> pubspec.yaml
1721
- name: Check Publish Warnings
1822
run: dart pub publish --dry-run
1923
- name: Publish

example/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ environment:
77
sdk: ^3.2.5
88

99
dependencies:
10-
nitric_sdk:
11-
path: ../
10+
nitric_sdk: ^1.0.0
1211
uuid: ^4.3.3
1312

1413
dev_dependencies:

lib/src/api/bucket.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ class Bucket {
3030
return File(this, key);
3131
}
3232

33+
/// Get a list of references to the files in the bucket. Optionally supply a [prefix] to filter by.
34+
Future<List<File>> files({String prefix = ""}) async {
35+
final request =
36+
$p.StorageListBlobsRequest(bucketName: name, prefix: prefix);
37+
38+
var resp = await _storageClient.listBlobs(request);
39+
40+
return resp.blobs.map((blob) => File(this, blob.key)).toList();
41+
}
42+
3343
/// Create a blob event subscription triggered on the [blobEventType] filtered by files that match the [keyPrefixFilter].
3444
Future<void> on(BlobEventType blobEventType, String keyPrefixFilter,
3545
BlobEventHandler handler) async {

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: nitric_sdk
22
description: A Dart SDK for creating Nitric applications
3-
version: 1.0.0
43
repository: https://github.com/nitrictech/dart_sdk
54

65
environment:

test/src/api/bucket_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,49 @@ void main() {
3232
expect(file.key, "fileName");
3333
});
3434

35+
test('Test get list of files with no prefix filter', () async {
36+
var req = StorageListBlobsRequest(bucketName: "bucketName", prefix: "");
37+
38+
var resp = StorageListBlobsResponse(
39+
blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]);
40+
41+
when(() => storageClient.listBlobs(req))
42+
.thenAnswer((_) => MockResponseFuture.value(resp));
43+
44+
var bucket = Bucket("bucketName", client: storageClient);
45+
46+
var blobs = await bucket.files();
47+
48+
verify(() => storageClient.listBlobs(req)).called(1);
49+
50+
expect(blobs.length, 3);
51+
expect(blobs[0].key, "blob-a");
52+
expect(blobs[1].key, "blob-b");
53+
expect(blobs[2].key, "blob-c");
54+
});
55+
56+
test('Test get list of files with prefix filter', () async {
57+
var req =
58+
StorageListBlobsRequest(bucketName: "bucketName", prefix: "blob-");
59+
60+
var resp = StorageListBlobsResponse(
61+
blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]);
62+
63+
when(() => storageClient.listBlobs(req))
64+
.thenAnswer((_) => MockResponseFuture.value(resp));
65+
66+
var bucket = Bucket("bucketName", client: storageClient);
67+
68+
var blobs = await bucket.files(prefix: "blob-");
69+
70+
verify(() => storageClient.listBlobs(req)).called(1);
71+
72+
expect(blobs.length, 3);
73+
expect(blobs[0].key, "blob-a");
74+
expect(blobs[1].key, "blob-b");
75+
expect(blobs[2].key, "blob-c");
76+
});
77+
3578
test('Test write to file', () async {
3679
var req = StorageWriteRequest(
3780
bucketName: "bucketName",

0 commit comments

Comments
 (0)