@zwa73/utils 1.0.248 → 1.0.249
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/UtilHttp.d.ts +10 -10
- package/dist/UtilHttp.js +27 -21
- package/package.json +1 -1
package/dist/UtilHttp.d.ts
CHANGED
|
@@ -237,15 +237,6 @@ export declare class UtilHttp<D extends Partial<RequestOption> & Required<Pick<R
|
|
|
237
237
|
/**附加的查询表单数据 */
|
|
238
238
|
query: QueryRequestData;
|
|
239
239
|
}) => MPromise<SendProcData>, A>;
|
|
240
|
-
/**发送form-data包提供的表单数据 */
|
|
241
|
-
sendFormData(): UtilHttp<D & {
|
|
242
|
-
headers: {
|
|
243
|
-
"Content-Type": "multipart/form-data";
|
|
244
|
-
};
|
|
245
|
-
}, (opt: RequestOption, arg: {
|
|
246
|
-
/**form-data包提供的FormData表单数据 */
|
|
247
|
-
formdata: FormData;
|
|
248
|
-
}) => MPromise<SendProcData>, A>;
|
|
249
240
|
/**发送表单 */
|
|
250
241
|
sendForm(): UtilHttp<D & {
|
|
251
242
|
headers: {
|
|
@@ -255,6 +246,15 @@ export declare class UtilHttp<D extends Partial<RequestOption> & Required<Pick<R
|
|
|
255
246
|
/**表单 */
|
|
256
247
|
form: QueryRequestData;
|
|
257
248
|
}) => MPromise<SendProcData>, A>;
|
|
249
|
+
/**发送form-data包提供的表单数据 */
|
|
250
|
+
sendFormData(): UtilHttp<D & {
|
|
251
|
+
headers: {
|
|
252
|
+
"Content-Type": "multipart/form-data";
|
|
253
|
+
};
|
|
254
|
+
}, (opt: RequestOption, arg: {
|
|
255
|
+
/**form-data包提供的FormData表单数据 */
|
|
256
|
+
formdata: FormData;
|
|
257
|
+
}) => MPromise<SendProcData>, A>;
|
|
258
258
|
/**发送文件 */
|
|
259
259
|
sendFile(): UtilHttp<D & {
|
|
260
260
|
headers: {
|
|
@@ -268,7 +268,7 @@ export declare class UtilHttp<D extends Partial<RequestOption> & Required<Pick<R
|
|
|
268
268
|
}) => MPromise<SendProcData>, A>;
|
|
269
269
|
sendNone(): UtilHttp<D, typeof SendNoneProc, A>;
|
|
270
270
|
/**自定的发送数据类型 */
|
|
271
|
-
sendRaw<T extends
|
|
271
|
+
sendRaw<T extends {}>(proc: SendProcCtor<T>): UtilHttp<D, typeof proc, A>;
|
|
272
272
|
/**发送请求
|
|
273
273
|
* @param datas - 数据对象
|
|
274
274
|
*/
|
package/dist/UtilHttp.js
CHANGED
|
@@ -268,26 +268,6 @@ class UtilHttp {
|
|
|
268
268
|
this._send = sendProc;
|
|
269
269
|
return this;
|
|
270
270
|
}
|
|
271
|
-
/**发送form-data包提供的表单数据 */
|
|
272
|
-
sendFormData() {
|
|
273
|
-
const sendProc = (opt, arg) => {
|
|
274
|
-
const { method } = opt;
|
|
275
|
-
const isPost = (method == "POST");
|
|
276
|
-
opt.headers = arg.formdata.getHeaders();
|
|
277
|
-
return {
|
|
278
|
-
proc: (req) => {
|
|
279
|
-
if (isPost)
|
|
280
|
-
arg.formdata.pipe(req);
|
|
281
|
-
else
|
|
282
|
-
req.end();
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
this._send = sendProc;
|
|
287
|
-
this._data.headers ??= {};
|
|
288
|
-
this._data.headers['Content-Type'] = 'multipart/form-data';
|
|
289
|
-
return this;
|
|
290
|
-
}
|
|
291
271
|
/**发送表单 */
|
|
292
272
|
sendForm() {
|
|
293
273
|
const snedProc = (opt, arg) => {
|
|
@@ -312,6 +292,29 @@ class UtilHttp {
|
|
|
312
292
|
this._data.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
313
293
|
return this;
|
|
314
294
|
}
|
|
295
|
+
/**发送form-data包提供的表单数据 */
|
|
296
|
+
sendFormData() {
|
|
297
|
+
const sendProc = (opt, arg) => {
|
|
298
|
+
const { method } = opt;
|
|
299
|
+
const isPost = (method == "POST");
|
|
300
|
+
opt.headers = {
|
|
301
|
+
...arg.formdata.getHeaders(),
|
|
302
|
+
...opt.headers,
|
|
303
|
+
};
|
|
304
|
+
return {
|
|
305
|
+
proc: (req) => {
|
|
306
|
+
if (isPost)
|
|
307
|
+
arg.formdata.pipe(req);
|
|
308
|
+
else
|
|
309
|
+
req.end();
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
this._send = sendProc;
|
|
314
|
+
this._data.headers ??= {};
|
|
315
|
+
this._data.headers['Content-Type'] = 'multipart/form-data';
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
315
318
|
/**发送文件 */
|
|
316
319
|
sendFile() {
|
|
317
320
|
const proc = (opt, arg) => {
|
|
@@ -321,7 +324,10 @@ class UtilHttp {
|
|
|
321
324
|
const formData = new form_data_1.default();
|
|
322
325
|
filename = filename ?? pathe_1.default.basename(filepath);
|
|
323
326
|
formData.append(filename, fs_1.default.createReadStream(filepath));
|
|
324
|
-
opt.headers =
|
|
327
|
+
opt.headers = {
|
|
328
|
+
...formData.getHeaders(),
|
|
329
|
+
...opt.headers
|
|
330
|
+
};
|
|
325
331
|
return {
|
|
326
332
|
proc: req => {
|
|
327
333
|
if (isPost)
|