Skip to content

Commit

Permalink
feat: putBucketInventory supports new fields (#1290)
Browse files Browse the repository at this point in the history
* 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 <csg01123119@alibaba-inc.com>
  • Loading branch information
shungang and csg01123119 authored Jul 31, 2024
1 parent 5a95778 commit 6bde1c2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 37 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint max-len: [0] */
// Ignore checking the js file generated by ts
const buckets = ['dataIndex.js'];
const ignorePatterns = ['lib/common/utils/*.js'].concat(buckets.map(item => `lib/common/bucket/${item}`));

module.exports = {
ignorePatterns,
extends: ['airbnb', 'eslint-config-ali/typescript', 'prettier'],
parserOptions: {
ecmaFeatures: {
Expand All @@ -16,7 +20,6 @@ module.exports = {
},
rules: {
indent: ['error', 2],
// override default options
'no-underscore-dangle': [0],
'no-plusplus': [0],
'no-return-await': [0],
Expand Down
96 changes: 64 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ try {
const putObjectResult = await store.put('your bucket name', 'your object name', {
headers: {
// The headers of this request
'header1': 'value1',
'header2': 'value2'
header1: 'value1',
header2: 'value2'
},
// 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.
additionalHeaders: ['additional header1', 'additional header2']
Expand Down Expand Up @@ -1489,7 +1489,8 @@ Success will return:
- res {Object} response info

```ts
type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
type Field =
'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
interface Inventory {
id: string;
isEnabled: true | false;
Expand Down Expand Up @@ -1538,7 +1539,18 @@ const inventory = {
frequency: 'Daily', // `WEEKLY` | `Daily`
includedObjectVersions: 'All', // `All` | `Current`
optionalFields: {
field: ['Size', 'LastModifiedDate', 'ETag', 'StorageClass', 'IsMultipartUploaded', 'EncryptionStatus']
field: [
'Size',
'LastModifiedDate',
'ETag',
'StorageClass',
'IsMultipartUploaded',
'EncryptionStatus',
'ObjectAcl',
'TaggingCount',
'ObjectType',
'Crc64'
]
}
};
Expand Down Expand Up @@ -2671,13 +2683,17 @@ const url = store.signatureUrl('ossdemo.txt', {
console.log(url);
// --------------------------------------------------
const url = store.signatureUrl('ossdemo.txt', {
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
}, false);
const url = store.signatureUrl(
'ossdemo.txt',
{
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
},
false
);
console.log(url);
// put operation
Expand Down Expand Up @@ -2750,13 +2766,17 @@ const url = await store.asyncSignatureUrl('ossdemo.txt', {
});
console.log(url);
// --------------------------------------------------
const url = await store.asyncSignatureUrl('ossdemo.txt', {
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
}, false);
const url = await store.asyncSignatureUrl(
'ossdemo.txt',
{
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
},
false
);
console.log(url);
// put operation
```
Expand Down Expand Up @@ -2799,28 +2819,40 @@ example:
const getObjectUrl = await store.signatureUrlV4('GET', 60, undefined, 'your obejct name');
console.log(getObjectUrl);
// --------------------------------------------------
const getObjectUrl = await store.signatureUrlV4('GET', 60, {
headers: {
'Cache-Control': 'no-cache'
const getObjectUrl = await store.signatureUrlV4(
'GET',
60,
{
headers: {
'Cache-Control': 'no-cache'
},
queries: {
versionId: 'version ID of your object'
}
},
queries: {
versionId: 'version ID of your object'
}
}, 'your obejct name', ['Cache-Control']);
'your obejct name',
['Cache-Control']
);
console.log(getObjectUrl);
// -------------------------------------------------
// PutObject
const putObejctUrl = await store.signatureUrlV4('PUT', 60, undefined, 'your obejct name');
console.log(putObejctUrl);
// --------------------------------------------------
const putObejctUrl = await store.signatureUrlV4('PUT', 60, {
headers: {
'Content-Type': 'text/plain',
'Content-MD5': 'xxx',
'Content-Length': 1
}
}, 'your obejct name', ['Content-Length']);
const putObejctUrl = await store.signatureUrlV4(
'PUT',
60,
{
headers: {
'Content-Type': 'text/plain',
'Content-MD5': 'xxx',
'Content-Length': 1
}
},
'your obejct name',
['Content-Length']
);
console.log(putObejctUrl);
```
Expand Down
2 changes: 1 addition & 1 deletion lib/common/bucket/putBucketInventory.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
declare type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
interface Inventory {
id: string;
isEnabled: true | false;
Expand Down
3 changes: 2 additions & 1 deletion lib/common/bucket/putBucketInventory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { checkBucketName } from '../utils/checkBucketName';
import { obj2xml } from '../utils/obj2xml';

type Field = 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus';
type Field =
'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';

interface Inventory {
id: string;
Expand Down
16 changes: 15 additions & 1 deletion test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,18 @@ describe('test/bucket.test.js', () => {
});
});
describe('inventory()', () => {
const field = [
'Size',
'LastModifiedDate',
'ETag',
'StorageClass',
'IsMultipartUploaded',
'EncryptionStatus',
'ObjectAcl',
'TaggingCount',
'ObjectType',
'Crc64'
];
const inventory = {
id: 'default',
isEnabled: false,
Expand All @@ -1328,7 +1340,7 @@ describe('test/bucket.test.js', () => {
frequency: 'Daily',
includedObjectVersions: 'All',
optionalFields: {
field: ['Size', 'LastModifiedDate']
field
}
};

Expand All @@ -1347,6 +1359,7 @@ describe('test/bucket.test.js', () => {
const inventoryRes = await store.listBucketInventory(bucket);
assert(Array.isArray(inventoryRes.inventoryList));
assert(inventoryRes.inventoryList.length === 1);
assert(inventoryRes.inventoryList[0].optionalFields.field.toString(), field.toString());
assert.strictEqual(inventoryRes.status, 200);
});
it('should put bucket inventory when no optionalFields or no field', async () => {
Expand Down Expand Up @@ -1399,6 +1412,7 @@ describe('test/bucket.test.js', () => {
it('should get bucket inventory by inventoryId', async () => {
try {
const result = await store.getBucketInventory(bucket, inventory.id);
assert(result.inventory.optionalFields.field.toString(), field.toString());
testGetInventory = result.inventory;
assert(includesConf(testGetInventory, inventory));
} catch (err) {
Expand Down

0 comments on commit 6bde1c2

Please sign in to comment.