@zwa73/utils 1.0.248 → 1.0.250

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.
@@ -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,12 +246,13 @@ 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, (opt: RequestOption, arg: {
251
+ /**form-data包提供的FormData表单数据 */
252
+ formdata: FormData;
253
+ }) => MPromise<SendProcData>, A>;
258
254
  /**发送文件 */
259
- sendFile(): UtilHttp<D & {
260
- headers: {
261
- "Content-Type": "multipart/form-data";
262
- };
263
- }, (opt: RequestOption, arg: {
255
+ sendFile(): UtilHttp<D, (opt: RequestOption, arg: {
264
256
  /**文件路径 */
265
257
  filepath: string;
266
258
  /**文件名 */
@@ -268,7 +260,7 @@ export declare class UtilHttp<D extends Partial<RequestOption> & Required<Pick<R
268
260
  }) => MPromise<SendProcData>, A>;
269
261
  sendNone(): UtilHttp<D, typeof SendNoneProc, A>;
270
262
  /**自定的发送数据类型 */
271
- sendRaw<T extends any[]>(proc: SendProcCtor<T>): UtilHttp<D, typeof proc, A>;
263
+ sendRaw<T extends {}>(proc: SendProcCtor<T>): UtilHttp<D, typeof proc, A>;
272
264
  /**发送请求
273
265
  * @param datas - 数据对象
274
266
  */
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,27 @@ 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
+ return this;
315
+ }
315
316
  /**发送文件 */
316
317
  sendFile() {
317
318
  const proc = (opt, arg) => {
@@ -321,7 +322,10 @@ class UtilHttp {
321
322
  const formData = new form_data_1.default();
322
323
  filename = filename ?? pathe_1.default.basename(filepath);
323
324
  formData.append(filename, fs_1.default.createReadStream(filepath));
324
- opt.headers = formData.getHeaders();
325
+ opt.headers = {
326
+ ...formData.getHeaders(),
327
+ ...opt.headers
328
+ };
325
329
  return {
326
330
  proc: req => {
327
331
  if (isPost)
@@ -332,8 +336,6 @@ class UtilHttp {
332
336
  };
333
337
  };
334
338
  this._send = proc;
335
- this._data.headers ??= {};
336
- this._data.headers['Content-Type'] = 'multipart/form-data';
337
339
  return this;
338
340
  }
339
341
  sendNone() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.248",
3
+ "version": "1.0.250",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {