@tarojs/taro-h5 3.6.0-canary.2 → 3.6.0-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { CallbackManager } from '../../utils/handler';
2
2
  import { NETWORK_TIMEOUT, setHeader, XHR_STATS } from './utils';
3
- const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
4
- let timeout;
3
+ const createDownloadTask = ({ url, header, withCredentials = true, timeout, success, error }) => {
4
+ let timeoutInter;
5
5
  const apiName = 'downloadFile';
6
6
  const xhr = new XMLHttpRequest();
7
7
  const callbackManager = {
@@ -37,7 +37,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
37
37
  });
38
38
  };
39
39
  xhr.onabort = () => {
40
- clearTimeout(timeout);
40
+ clearTimeout(timeoutInter);
41
41
  error({
42
42
  errMsg: `${apiName}:fail abort`
43
43
  });
@@ -55,7 +55,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
55
55
  };
56
56
  const send = () => {
57
57
  xhr.send();
58
- timeout = setTimeout(() => {
58
+ timeoutInter = setTimeout(() => {
59
59
  xhr.onabort = null;
60
60
  xhr.onload = null;
61
61
  xhr.onprogress = null;
@@ -65,7 +65,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
65
65
  error({
66
66
  errMsg: `${apiName}:fail timeout`
67
67
  });
68
- }, NETWORK_TIMEOUT);
68
+ }, timeout || NETWORK_TIMEOUT);
69
69
  };
70
70
  send();
71
71
  /**
@@ -100,13 +100,14 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
100
100
  * 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
101
101
  * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
102
102
  */
103
- export const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
103
+ export const downloadFile = ({ url, header, withCredentials, timeout, success, fail, complete }) => {
104
104
  let task;
105
105
  const result = new Promise((resolve, reject) => {
106
106
  task = createDownloadTask({
107
107
  url,
108
108
  header,
109
109
  withCredentials,
110
+ timeout,
110
111
  success: res => {
111
112
  success && success(res);
112
113
  complete && complete(res);
package/dist/index.cjs.js CHANGED
@@ -2660,8 +2660,8 @@ const convertObjectUrlToBlob = url => {
2660
2660
  });
2661
2661
  };
2662
2662
 
2663
- const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
2664
- let timeout;
2663
+ const createDownloadTask = ({ url, header, withCredentials = true, timeout, success, error }) => {
2664
+ let timeoutInter;
2665
2665
  const apiName = 'downloadFile';
2666
2666
  const xhr = new XMLHttpRequest();
2667
2667
  const callbackManager = {
@@ -2697,7 +2697,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
2697
2697
  });
2698
2698
  };
2699
2699
  xhr.onabort = () => {
2700
- clearTimeout(timeout);
2700
+ clearTimeout(timeoutInter);
2701
2701
  error({
2702
2702
  errMsg: `${apiName}:fail abort`
2703
2703
  });
@@ -2715,7 +2715,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
2715
2715
  };
2716
2716
  const send = () => {
2717
2717
  xhr.send();
2718
- timeout = setTimeout(() => {
2718
+ timeoutInter = setTimeout(() => {
2719
2719
  xhr.onabort = null;
2720
2720
  xhr.onload = null;
2721
2721
  xhr.onprogress = null;
@@ -2725,7 +2725,7 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
2725
2725
  error({
2726
2726
  errMsg: `${apiName}:fail timeout`
2727
2727
  });
2728
- }, NETWORK_TIMEOUT);
2728
+ }, timeout || NETWORK_TIMEOUT);
2729
2729
  };
2730
2730
  send();
2731
2731
  /**
@@ -2760,13 +2760,14 @@ const createDownloadTask = ({ url, header, withCredentials = true, success, erro
2760
2760
  * 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
2761
2761
  * 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
2762
2762
  */
2763
- const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
2763
+ const downloadFile = ({ url, header, withCredentials, timeout, success, fail, complete }) => {
2764
2764
  let task;
2765
2765
  const result = new Promise((resolve, reject) => {
2766
2766
  task = createDownloadTask({
2767
2767
  url,
2768
2768
  header,
2769
2769
  withCredentials,
2770
+ timeout,
2770
2771
  success: res => {
2771
2772
  success && success(res);
2772
2773
  complete && complete(res);