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

chore: develop to master by xutao #1244

Merged
merged 13 commits into from
Sep 4, 2023
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'
shungang marked this conversation as resolved.
Show resolved Hide resolved
);
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
Loading