Skip to content

Commit 6bde1c2

Browse files
shungangcsg01123119
and
csg01123119
authored
feat: putBucketInventory supports new fields (#1290)
* feat: add putBucketInventory ObjectAcl | TaggingCount | ObjectType | Crc64 * feat: putBucketInventory supports new fields * feat: putBucketInventory supports new fields * feat: putBucketInventory supports new fields --------- Co-authored-by: csg01123119 <[email protected]>
1 parent 5a95778 commit 6bde1c2

File tree

5 files changed

+87
-37
lines changed

5 files changed

+87
-37
lines changed

.eslintrc.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
/* eslint max-len: [0] */
1+
// Ignore checking the js file generated by ts
2+
const buckets = ['dataIndex.js'];
3+
const ignorePatterns = ['lib/common/utils/*.js'].concat(buckets.map(item => `lib/common/bucket/${item}`));
4+
25
module.exports = {
6+
ignorePatterns,
37
extends: ['airbnb', 'eslint-config-ali/typescript', 'prettier'],
48
parserOptions: {
59
ecmaFeatures: {
@@ -16,7 +20,6 @@ module.exports = {
1620
},
1721
rules: {
1822
indent: ['error', 2],
19-
// override default options
2023
'no-underscore-dangle': [0],
2124
'no-plusplus': [0],
2225
'no-return-await': [0],

README.md

+64-32
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ try {
460460
const putObjectResult = await store.put('your bucket name', 'your object name', {
461461
headers: {
462462
// The headers of this request
463-
'header1': 'value1',
464-
'header2': 'value2'
463+
header1: 'value1',
464+
header2: 'value2'
465465
},
466466
// The keys of the request headers that need to be calculated into the V4 signature. Please ensure that these additional headers are included in the request headers.
467467
additionalHeaders: ['additional header1', 'additional header2']
@@ -1489,7 +1489,8 @@ Success will return:
14891489
- res {Object} response info
14901490

14911491
```ts
1492-
type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
1492+
type Field =
1493+
'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
14931494
interface Inventory {
14941495
id: string;
14951496
isEnabled: true | false;
@@ -1538,7 +1539,18 @@ const inventory = {
15381539
frequency: 'Daily', // `WEEKLY` | `Daily`
15391540
includedObjectVersions: 'All', // `All` | `Current`
15401541
optionalFields: {
1541-
field: ['Size', 'LastModifiedDate', 'ETag', 'StorageClass', 'IsMultipartUploaded', 'EncryptionStatus']
1542+
field: [
1543+
'Size',
1544+
'LastModifiedDate',
1545+
'ETag',
1546+
'StorageClass',
1547+
'IsMultipartUploaded',
1548+
'EncryptionStatus',
1549+
'ObjectAcl',
1550+
'TaggingCount',
1551+
'ObjectType',
1552+
'Crc64'
1553+
]
15421554
}
15431555
};
15441556

@@ -2671,13 +2683,17 @@ const url = store.signatureUrl('ossdemo.txt', {
26712683
console.log(url);
26722684
26732685
// --------------------------------------------------
2674-
const url = store.signatureUrl('ossdemo.txt', {
2675-
expires: 3600,
2676-
response: {
2677-
'content-type': 'text/custom',
2678-
'content-disposition': 'attachment'
2679-
}
2680-
}, false);
2686+
const url = store.signatureUrl(
2687+
'ossdemo.txt',
2688+
{
2689+
expires: 3600,
2690+
response: {
2691+
'content-type': 'text/custom',
2692+
'content-disposition': 'attachment'
2693+
}
2694+
},
2695+
false
2696+
);
26812697
console.log(url);
26822698
26832699
// put operation
@@ -2750,13 +2766,17 @@ const url = await store.asyncSignatureUrl('ossdemo.txt', {
27502766
});
27512767
console.log(url);
27522768
// --------------------------------------------------
2753-
const url = await store.asyncSignatureUrl('ossdemo.txt', {
2754-
expires: 3600,
2755-
response: {
2756-
'content-type': 'text/custom',
2757-
'content-disposition': 'attachment'
2758-
}
2759-
}, false);
2769+
const url = await store.asyncSignatureUrl(
2770+
'ossdemo.txt',
2771+
{
2772+
expires: 3600,
2773+
response: {
2774+
'content-type': 'text/custom',
2775+
'content-disposition': 'attachment'
2776+
}
2777+
},
2778+
false
2779+
);
27602780
console.log(url);
27612781
// put operation
27622782
```
@@ -2799,28 +2819,40 @@ example:
27992819
const getObjectUrl = await store.signatureUrlV4('GET', 60, undefined, 'your obejct name');
28002820
console.log(getObjectUrl);
28012821
// --------------------------------------------------
2802-
const getObjectUrl = await store.signatureUrlV4('GET', 60, {
2803-
headers: {
2804-
'Cache-Control': 'no-cache'
2822+
const getObjectUrl = await store.signatureUrlV4(
2823+
'GET',
2824+
60,
2825+
{
2826+
headers: {
2827+
'Cache-Control': 'no-cache'
2828+
},
2829+
queries: {
2830+
versionId: 'version ID of your object'
2831+
}
28052832
},
2806-
queries: {
2807-
versionId: 'version ID of your object'
2808-
}
2809-
}, 'your obejct name', ['Cache-Control']);
2833+
'your obejct name',
2834+
['Cache-Control']
2835+
);
28102836
console.log(getObjectUrl);
28112837
28122838
// -------------------------------------------------
28132839
// PutObject
28142840
const putObejctUrl = await store.signatureUrlV4('PUT', 60, undefined, 'your obejct name');
28152841
console.log(putObejctUrl);
28162842
// --------------------------------------------------
2817-
const putObejctUrl = await store.signatureUrlV4('PUT', 60, {
2818-
headers: {
2819-
'Content-Type': 'text/plain',
2820-
'Content-MD5': 'xxx',
2821-
'Content-Length': 1
2822-
}
2823-
}, 'your obejct name', ['Content-Length']);
2843+
const putObejctUrl = await store.signatureUrlV4(
2844+
'PUT',
2845+
60,
2846+
{
2847+
headers: {
2848+
'Content-Type': 'text/plain',
2849+
'Content-MD5': 'xxx',
2850+
'Content-Length': 1
2851+
}
2852+
},
2853+
'your obejct name',
2854+
['Content-Length']
2855+
);
28242856
console.log(putObejctUrl);
28252857
```
28262858

lib/common/bucket/putBucketInventory.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
1+
declare type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
22
interface Inventory {
33
id: string;
44
isEnabled: true | false;

lib/common/bucket/putBucketInventory.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { checkBucketName } from '../utils/checkBucketName';
22
import { obj2xml } from '../utils/obj2xml';
33

4-
type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
4+
type Field =
5+
'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
56

67
interface Inventory {
78
id: string;

test/node/bucket.test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,18 @@ describe('test/bucket.test.js', () => {
13141314
});
13151315
});
13161316
describe('inventory()', () => {
1317+
const field = [
1318+
'Size',
1319+
'LastModifiedDate',
1320+
'ETag',
1321+
'StorageClass',
1322+
'IsMultipartUploaded',
1323+
'EncryptionStatus',
1324+
'ObjectAcl',
1325+
'TaggingCount',
1326+
'ObjectType',
1327+
'Crc64'
1328+
];
13171329
const inventory = {
13181330
id: 'default',
13191331
isEnabled: false,
@@ -1328,7 +1340,7 @@ describe('test/bucket.test.js', () => {
13281340
frequency: 'Daily',
13291341
includedObjectVersions: 'All',
13301342
optionalFields: {
1331-
field: ['Size', 'LastModifiedDate']
1343+
field
13321344
}
13331345
};
13341346

@@ -1347,6 +1359,7 @@ describe('test/bucket.test.js', () => {
13471359
const inventoryRes = await store.listBucketInventory(bucket);
13481360
assert(Array.isArray(inventoryRes.inventoryList));
13491361
assert(inventoryRes.inventoryList.length === 1);
1362+
assert(inventoryRes.inventoryList[0].optionalFields.field.toString(), field.toString());
13501363
assert.strictEqual(inventoryRes.status, 200);
13511364
});
13521365
it('should put bucket inventory when no optionalFields or no field', async () => {
@@ -1399,6 +1412,7 @@ describe('test/bucket.test.js', () => {
13991412
it('should get bucket inventory by inventoryId', async () => {
14001413
try {
14011414
const result = await store.getBucketInventory(bucket, inventory.id);
1415+
assert(result.inventory.optionalFields.field.toString(), field.toString());
14021416
testGetInventory = result.inventory;
14031417
assert(includesConf(testGetInventory, inventory));
14041418
} catch (err) {

0 commit comments

Comments
 (0)