Skip to content

Commit 19f1454

Browse files
committed
code refactor
1 parent d749e13 commit 19f1454

3 files changed

Lines changed: 14 additions & 23 deletions

File tree

storage/listObjectContexts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// sample-metadata:
1818
// title: List Objects with Context Filter
1919
// description: Lists objects in a bucket that match specific custom contexts.
20-
// usage: node listObjectsWithContextFilter.js <BUCKET_NAME>
20+
// usage: node listObjectContexts.js <BUCKET_NAME>
2121

2222
/**
2323
* This application demonstrates how to list objects in a bucket while filtering

storage/setObjectContexts.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,21 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') {
4343

4444
async function setObjectContexts() {
4545
const file = storage.bucket(bucketName).file(fileName);
46-
try {
47-
// Create/Update Object Contexts
48-
// Object Contexts live in the 'contexts' field, not the 'metadata' field.
49-
const [metadata] = await file.setMetadata({
50-
contexts: {
51-
custom: {
52-
'team-owner': {value: 'storage-team'},
53-
priority: {value: 'high'},
54-
},
46+
47+
// Create/Update Object Contexts
48+
// Object Contexts live in the 'contexts' field, not the 'metadata' field.
49+
const [metadata] = await file.setMetadata({
50+
contexts: {
51+
custom: {
52+
'team-owner': {value: 'storage-team'},
53+
priority: {value: 'high'},
5554
},
56-
});
55+
},
56+
});
57+
58+
console.log(`Updated Object Contexts for ${fileName}:`);
59+
console.log(JSON.stringify(metadata.contexts, null, 2));
5760

58-
console.log(`Updated Object Contexts for ${fileName}:`);
59-
console.log(JSON.stringify(metadata.contexts, null, 2));
60-
} catch (error) {
61-
console.error(
62-
'Error executing set object contexts:',
63-
error.message || error
64-
);
65-
}
6661
// Delete a specific key from the context:
6762
// We send 'null' for the specific key we want to remove.
6863
await file.setMetadata({

storage/system-test/files.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ describe('file', () => {
114114
'Files matching filter [contexts."priority"="high"]'
115115
);
116116
assert.include(output, ` - ${fileName}`);
117-
assert.include(
118-
output,
119-
'Files matching filter [contexts."priority"="high"]'
120-
);
121117

122118
// Testing Existence of Key (contexts."key":*)
123119
assert.include(output, 'Files with the "team-owner" context key');

0 commit comments

Comments
 (0)