Skip to content

Commit

Permalink
chore: develop to master by xutao (#1244)
Browse files Browse the repository at this point in the history
* chore: adjust download  request hints (#1061)

* chore: adjust download hints

* chore: adjust download hints

* chore: some optimized (#1062)

- add head method warning
- adjust PR githubCi

* chore(develop): remove cleanbucket workflow (#1094)

* feat(develop): ios dingding add default content-type (#1070)

* feat(develop): ios dingding add default content-type

* feat(develop): ios dingding add default content-type

* feat(develop): ios dingding add default content-type

* feat(develop): ios dingding add default content-type

* feat(develop): ios dingding add default content-type

* feat(develop): ios dingding add default content-type

* chore: remove remove redundant judgments

* resolve master and develop conflict (#1122)

Co-authored-by: xt01102058 <xt01102058@alibaba-inc.com>

* resolve master and develop conflict

* chore: marge develop to master

* test: fix test ConnectionTimeoutError bug

* chore: add put() timeout unit

* chore: optimize the translation of readme.md ResponseTimeoutError

---------

Co-authored-by: moca_tao7 <moca_tao7@foxmail.com>
Co-authored-by: xt01102058 <xt01102058@alibaba-inc.com>
Co-authored-by: PeterRao <peizerao@gmail.com>
Co-authored-by: csg01123119 <csg01123119@alibaba-inc.com>
  • Loading branch information
5 people committed Sep 4, 2023
1 parent c1f06c5 commit 13a2691
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 6 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ parameters:
- name {String} object name store on OSS
- file {String|Buffer|ReadStream|File(only support Browser)|Blob(only support Browser)} object local path, content buffer or ReadStream content instance use in Node, Blob and html5 File
- [options] {Object} optional parameters
- [timeout] {Number} the operation timeout
- [timeout] {Number} the operation timeout (ms)
- [mime] {String} custom mime, will send with `Content-Type` entity header
- [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
e.g.: `{ uid: 123, pid: 110 }`
Expand Down Expand Up @@ -4557,7 +4557,29 @@ Each error return by OSS server will contains these properties:
you can send this request id to OSS engineer to find out what's happend.
- hostId {String} OSS cluster name for this request

The following table lists the OSS error codes:
### ResponseTimeoutError

The default timeout is 60 seconds. Please set the timeout as needed. The timeout unit is milliseconds.

```javascript
client.get('example.txt', { timeout: 60000 * 2 });
client.get('example.txt', { headers: { Range: `bytes=0-${1024 * 1024 * 100}` } }); // Download the first 100MB
```

### ConnectionTimeoutError

The network link timed out. Please check the network status. If there is no problem with the network, please reduce the partSize or increase the timeout.

```javascript
const client = new OSS({ ak, sk, retryMax: 10 });
client.multipartUpload('example.txt', { timeout: 60000 * 2 });
client.multipartUpload('example.txt', { partSize: 1024 * 512 }); // partSize 512KB
```

### The following table lists the OSS error codes:

[More code info](https://help.aliyun.com/knowledge_detail/32005.html)

Expand Down
9 changes: 8 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ async function request(params) {
}

if (err.name === 'ResponseTimeoutError') {
err.message = `${err.message.split(',')[0]}, please increase the timeout or use multipartDownload.`;
err.message = `${
err.message.split(',')[0]
}, please increase the timeout, see more details at https://github.com/ali-sdk/ali-oss#responsetimeouterror`;
}
if (err.name === 'ConnectionTimeoutError') {
err.message = `${
err.message.split(',')[0]
}, please increase the timeout or reduce the partSize, see more details at https://github.com/ali-sdk/ali-oss#connectiontimeouterror`;
}
throw err;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/common/object/head.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { checkEnv } = require('../utils/checkEnv');
const proto = exports;
/**
* head
Expand All @@ -7,6 +8,9 @@ const proto = exports;
*/

proto.head = async function head(name, options = {}) {
checkEnv(
'Because HeadObject has gzip enabled, head cannot get the file size correctly. If you need to get the file size, please use getObjectMeta'
);
options.subres = Object.assign({}, options.subres);
if (options.versionId) {
options.subres.versionId = options.versionId;
Expand Down
1 change: 1 addition & 0 deletions lib/common/utils/checkEnv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function checkEnv(msg: string): void;
9 changes: 9 additions & 0 deletions lib/common/utils/checkEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEnv = void 0;
function checkEnv(msg) {
if (process.browser) {
console.warn(msg);
}
}
exports.checkEnv = checkEnv;
5 changes: 5 additions & 0 deletions lib/common/utils/checkEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function checkEnv(msg: string) {
if (process.browser) {
console.warn(msg);
}
}
4 changes: 4 additions & 0 deletions lib/common/utils/createRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { encoder } = require('./encoder');
const { isIP } = require('./isIP');
const { setRegion } = require('./setRegion');
const { getReqUrl } = require('../client/getReqUrl');
const { isDingTalk } = require('./isDingTalk');
function getHeader(headers, name) {
return headers[name] || headers[name.toLowerCase()];
}
Expand Down Expand Up @@ -43,6 +44,9 @@ function createRequest(params) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
}
else if (isDingTalk()) {
headers['Content-Type'] = 'application/octet-stream';
}
else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/common/utils/createRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { encoder } = require('./encoder');
const { isIP } = require('./isIP');
const { setRegion } = require('./setRegion');
const { getReqUrl } = require('../client/getReqUrl');
const { isDingTalk } = require('./isDingTalk');

interface Headers {
[propName: string]: any;
Expand Down Expand Up @@ -58,6 +59,8 @@ export function createRequest(this: any, params) {
if (!getHeader(headers, 'Content-Type')) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
} else if (isDingTalk()) {
headers['Content-Type'] = 'application/octet-stream';
} else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
Expand Down
1 change: 1 addition & 0 deletions lib/common/utils/isDingTalk.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function isDingTalk(): boolean;
10 changes: 10 additions & 0 deletions lib/common/utils/isDingTalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDingTalk = void 0;
function isDingTalk() {
if (process.browser && window.navigator.userAgent.toLowerCase().includes('aliapp(dingtalk')) {
return true;
}
return false;
}
exports.isDingTalk = isDingTalk;
6 changes: 6 additions & 0 deletions lib/common/utils/isDingTalk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function isDingTalk() {
if (process.browser && window.navigator.userAgent.toLowerCase().includes('aliapp(dingtalk')) {
return true;
}
return false;
}
3 changes: 0 additions & 3 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,6 @@ describe('browser', () => {
timeout: 300
};
try {
setTimeout(() => {
options.timeout = 60000;
}, 200);
await store.put(name, body, options);
assert(false);
} catch (error) {
Expand Down

0 comments on commit 13a2691

Please sign in to comment.