@zwa73/utils 1.0.177 → 1.0.179

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.
package/dist/UtilCom.d.ts CHANGED
@@ -39,7 +39,7 @@ export type GetReqData = NodeJS.Dict<string | number | boolean | readonly string
39
39
  export declare namespace UtilCom {
40
40
  /**网络请求
41
41
  * @param comReqOpt - 网络请求选项
42
- * @param procReq - 请求处理函数
42
+ * @param procReq - 请求处理函数 需调用req.end()
43
43
  * @param reduceData - 数据处理函数
44
44
  * @param initData - 初始数据
45
45
  */
package/dist/UtilCom.js CHANGED
@@ -14,7 +14,7 @@ var UtilCom;
14
14
  (function (UtilCom) {
15
15
  /**网络请求
16
16
  * @param comReqOpt - 网络请求选项
17
- * @param procReq - 请求处理函数
17
+ * @param procReq - 请求处理函数 需调用req.end()
18
18
  * @param reduceData - 数据处理函数
19
19
  * @param initData - 初始数据
20
20
  */
@@ -30,7 +30,6 @@ var UtilCom;
30
30
  res.setTimeout(timeLimit, () => {
31
31
  UtilLogger_1.SLogger.warn(`${flagName} 接收反馈超时(timeLimit): ${timeLimit} ms`);
32
32
  resolve(undefined);
33
- return;
34
33
  });
35
34
  }
36
35
  let mergedata = initData;
@@ -39,7 +38,6 @@ var UtilCom;
39
38
  res.on('error', (e) => {
40
39
  UtilLogger_1.SLogger.warn(`${flagName} 接收反馈错误:${e}`);
41
40
  resolve(undefined);
42
- return;
43
41
  });
44
42
  res.on('end', () => {
45
43
  resolve({
@@ -75,7 +73,6 @@ var UtilCom;
75
73
  resolve(undefined);
76
74
  });
77
75
  await procReq(req);
78
- req.end();
79
76
  });
80
77
  }
81
78
  UtilCom.comReq = comReq;
@@ -87,11 +84,18 @@ var UtilCom;
87
84
  async function jsonReq(comReqOpt, reqData) {
88
85
  const { method } = comReqOpt;
89
86
  const isPost = (method == "POST");
90
- if (!isPost && reqData != undefined)
91
- comReqOpt.path += querystring_1.default.stringify(reqData);
87
+ if (!isPost && reqData != undefined) {
88
+ const queryString = querystring_1.default.stringify(reqData);
89
+ if (queryString) {
90
+ // 检查当前路径是否已经包含问号
91
+ const separator = comReqOpt.path.includes('?') ? '&' : '?';
92
+ comReqOpt.path += separator + queryString;
93
+ }
94
+ }
92
95
  const procReq = (req) => {
93
96
  if (isPost)
94
97
  req.write(JSON.stringify(reqData));
98
+ req.end();
95
99
  };
96
100
  const reduceData = (acc, data) => acc + data;
97
101
  const result = await comReq(comReqOpt, procReq, reduceData, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.177",
3
+ "version": "1.0.179",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -56,7 +56,7 @@ export namespace UtilCom{
56
56
 
57
57
  /**网络请求
58
58
  * @param comReqOpt - 网络请求选项
59
- * @param procReq - 请求处理函数
59
+ * @param procReq - 请求处理函数 需调用req.end()
60
60
  * @param reduceData - 数据处理函数
61
61
  * @param initData - 初始数据
62
62
  */
@@ -80,7 +80,6 @@ export async function comReq<T>(
80
80
  res.setTimeout(timeLimit!, ()=>{
81
81
  SLogger.warn(`${flagName} 接收反馈超时(timeLimit): ${timeLimit} ms`);
82
82
  resolve(undefined);
83
- return;
84
83
  });
85
84
  }
86
85
 
@@ -91,7 +90,6 @@ export async function comReq<T>(
91
90
  res.on('error',(e)=>{
92
91
  SLogger.warn(`${flagName} 接收反馈错误:${e}`);
93
92
  resolve(undefined);
94
- return;
95
93
  });
96
94
 
97
95
  res.on('end',()=>{
@@ -130,8 +128,6 @@ export async function comReq<T>(
130
128
  });
131
129
 
132
130
  await procReq(req);
133
-
134
- req.end();
135
131
  });
136
132
  }
137
133
 
@@ -147,10 +143,18 @@ async function jsonReq<T extends ComReqOpt>(
147
143
  const {method} = comReqOpt;
148
144
  const isPost = (method=="POST");
149
145
 
150
- if(!isPost && reqData!=undefined) comReqOpt.path+=qs.stringify(reqData as GetReqData);
146
+ if (!isPost && reqData != undefined) {
147
+ const queryString = qs.stringify(reqData as GetReqData);
148
+ if (queryString) {
149
+ // 检查当前路径是否已经包含问号
150
+ const separator = comReqOpt.path.includes('?') ? '&' : '?';
151
+ comReqOpt.path += separator + queryString;
152
+ }
153
+ }
151
154
 
152
155
  const procReq = (req:http.ClientRequest)=>{
153
156
  if(isPost) req.write(JSON.stringify(reqData));
157
+ req.end();
154
158
  }
155
159
 
156
160
  const reduceData = (acc:string,data:string)=>acc+data;