Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: browser test and listV2 docs #901

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ All operation use es7 async/await to implement. All api is async function.

- [Object Operations](#object-operations)
- [.list(query[, options])](#listquery-options)
- [.listV2(query[, options])](#listV2query-options)
- [.getBucketVersions(query[, options])](#getBucketVersionsquery-options)
- [.put(name, file[, options])](#putname-file-options)
- [.putStream(name, stream[, options])](#putstreamname-stream-options)
Expand Down Expand Up @@ -2289,6 +2290,83 @@ const result = await store.list({
console.log(result.objects);
```

### .listV2(query[, options])

List objects in the bucket.(recommended)

parameters:

- [query] {Object} query parameters, default is `null`
- [prefix] {String} search object using `prefix` key
- [continuationToken] {String} search start from `continuationToken`, including `continuationToken` key
- [delimiter] {String} delimiter search scope
e.g. `/` only search current dir, not including subdir
- [max-keys] {String|Number} max objects, default is `100`, limit to `1000`
- [start-after] {String} specifies the Start-after value from which to start the list. The names of objects are returned in alphabetical order.
- [fetch-owner] {Boolean} specifies whether to include the owner information in the response.
- [options] {Object} optional parameters
- [timeout] {Number} the operation timeout

Success will return objects list on `objects` properties.

- objects {Array<ObjectMeta>} object meta info list
Each `ObjectMeta` will contains blow properties:
- name {String} object name on oss
- url {String} resource url
- lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
- etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
- type {String} object type, e.g.: `Normal`
- size {Number} object size, e.g.: `344606`
- storageClass {String} storage class type, e.g.: `Standard`
- owner {Object|null} object owner, including `id` and `displayName`
- prefixes {Array<String>} prefix list
- isTruncated {Boolean} truncate or not
- nextContinuationToken {String} next continuation-token string
- res {Object} response info, including
- status {Number} response status
- headers {Object} response headers
- size {Number} response size
- rt {Number} request total use time (ms)

- List top 10 objects

```js
const result = await store.listV2({
'max-keys': 10
});
console.log(result.objects);
```

- List `fun/` dir including subdirs objects

```js
const result = await store.listV2({
prefix: 'fun/'
});
console.log(result.objects);
```

- List `fun/` dir objects, not including subdirs

```js
const result = await store.listV2({
prefix: 'fun/',
delimiter: '/'
});
console.log(result.objects);
```

- List `a/` dir objects, after `a/b` and include `a/b`

```js
const result = await store.listV2({
delimiter: '/',
prefix: 'a/',
'start-after': 'b'
});
console.log(result.objects);
```

### .getBucketVersions(query[, options])

List the version information of all objects in the bucket, including the delete marker (Delete Marker).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test-cov": "nyc --reporter=lcov node_modules/.bin/_mocha -t 60000 -r thunk-mocha -r should test/node/*.test.js test/node/**/*.test.js",
"jshint": "jshint .",
"autod": "autod",
"build-test": "MINIFY=1 node browser-build.js > test/browser/build/aliyun-oss-sdk.min.js && node task/browser-test-build.js > test/browser/build/tests.js",
"build-test": "MINIFY=1 node browser-build.js > test/browser/build/aliyun-oss-sdk.min.js && node -r dotenv/config task/browser-test-build.js > test/browser/build/tests.js",
"browser-test": "npm run build-test && karma start",
"build-dist": "npm run tsc && node browser-build.js > dist/aliyun-oss-sdk.js && MINIFY=1 node browser-build.js > dist/aliyun-oss-sdk.min.js",
"publish-to-npm": "node publish-npm-check.js && npm publish",
Expand Down
7 changes: 5 additions & 2 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,10 @@ describe('browser', () => {

describe('listV2()', () => {
let listPrefix;
let store;
before(async () => {
listPrefix = `${prefix}ali-sdk/listV2/`;
store = oss(ossConfig);
await store.put(`${listPrefix}oss.jpg`, Buffer.from('oss.jpg'));
await store.put(`${listPrefix}fun/test.jpg`, Buffer.from('fun/test.jpg'));
await store.put(`${listPrefix}fun/movie/001.avi`, Buffer.from('fun/movie/001.avi'));
Expand Down Expand Up @@ -2060,14 +2062,15 @@ describe('browser', () => {

it('should succeed when put with filename', async () => {
const name = `ali-oss-test-retry-file-${Date.now()}`;
const res = await store.put(name, );
const file = new File([1, 2, 3, 4, 5, 6, 7], name);
const res = await store.put(name, file);
assert.strictEqual(res.res.status, 200);
assert.strictEqual(testRetryCount, RETRY_MAX);
const onlineFile = await store.get(name);
assert.strictEqual(onlineFile.content.toString(), '1234567');
});

it.only('should fail when putStream', async () => {
it('should fail when putStream', async () => {
autoRestoreWhenRETRY_LIMIE = false;
const name = `ali-oss-test-retry-file-${Date.now()}`;
const file = new File([1, 2, 3, 4, 5, 6, 7], name);
Expand Down