@maiyunnet/kebab 7.9.0 → 7.10.0

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/doc/kebab-rag.md CHANGED
@@ -1385,7 +1385,7 @@ index/variables/VER.md
1385
1385
 
1386
1386
  # Variable: VER
1387
1387
 
1388
- > `const` **VER**: `"7.9.0"` = `'7.9.0'`
1388
+ > `const` **VER**: `"7.10.0"` = `'7.10.0'`
1389
1389
 
1390
1390
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1391
1391
 
@@ -9864,7 +9864,7 @@ lib/net/formdata/classes/FormData.md
9864
9864
 
9865
9865
  # Class: FormData
9866
9866
 
9867
- Defined in: [lib/net/formdata.ts:22](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L22)
9867
+ Defined in: [lib/net/formdata.ts:37](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L37)
9868
9868
 
9869
9869
  ## Extends
9870
9870
 
@@ -9898,7 +9898,7 @@ Defined in: node\_modules/@types/node/stream.d.ts:98
9898
9898
 
9899
9899
  > **\_read**(): `void`
9900
9900
 
9901
- Defined in: [lib/net/formdata.ts:115](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L115)
9901
+ Defined in: [lib/net/formdata.ts:146](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L146)
9902
9902
 
9903
9903
  间隔读取(on data 或 pipe 触发)
9904
9904
 
@@ -9916,7 +9916,7 @@ Defined in: [lib/net/formdata.ts:115](https://github.com/maiyunnet/kebab/blob/ma
9916
9916
 
9917
9917
  > **getBoundary**(): `string`
9918
9918
 
9919
- Defined in: [lib/net/formdata.ts:93](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L93)
9919
+ Defined in: [lib/net/formdata.ts:124](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L124)
9920
9920
 
9921
9921
  获取 boundary
9922
9922
 
@@ -9930,7 +9930,7 @@ Defined in: [lib/net/formdata.ts:93](https://github.com/maiyunnet/kebab/blob/mas
9930
9930
 
9931
9931
  > **getLength**(): `number`
9932
9932
 
9933
- Defined in: [lib/net/formdata.ts:100](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L100)
9933
+ Defined in: [lib/net/formdata.ts:131](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L131)
9934
9934
 
9935
9935
  获取总字节长度
9936
9936
 
@@ -9944,7 +9944,7 @@ Defined in: [lib/net/formdata.ts:100](https://github.com/maiyunnet/kebab/blob/ma
9944
9944
 
9945
9945
  > **getSent**(): `number`
9946
9946
 
9947
- Defined in: [lib/net/formdata.ts:107](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L107)
9947
+ Defined in: [lib/net/formdata.ts:138](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L138)
9948
9948
 
9949
9949
  获取已发送的字节长度
9950
9950
 
@@ -9954,11 +9954,45 @@ Defined in: [lib/net/formdata.ts:107](https://github.com/maiyunnet/kebab/blob/ma
9954
9954
 
9955
9955
  ***
9956
9956
 
9957
+ ### putBuffer()
9958
+
9959
+ > **putBuffer**(`key`, `buffer`, `fname`): `void`
9960
+
9961
+ Defined in: [lib/net/formdata.ts:109](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L109)
9962
+
9963
+ 添加 Buffer 数据
9964
+
9965
+ #### Parameters
9966
+
9967
+ ##### key
9968
+
9969
+ `string`
9970
+
9971
+
9972
+
9973
+ ##### buffer
9974
+
9975
+ `Buffer`
9976
+
9977
+ Buffer 数据
9978
+
9979
+ ##### fname
9980
+
9981
+ `string`
9982
+
9983
+ 文件名
9984
+
9985
+ #### Returns
9986
+
9987
+ `void`
9988
+
9989
+ ***
9990
+
9957
9991
  ### putFile()
9958
9992
 
9959
9993
  > **putFile**(`key`, `path`, `fname?`): `Promise`\<`boolean`\>
9960
9994
 
9961
- Defined in: [lib/net/formdata.ts:67](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L67)
9995
+ Defined in: [lib/net/formdata.ts:81](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L81)
9962
9996
 
9963
9997
  添加文件
9964
9998
 
@@ -9992,7 +10026,7 @@ Defined in: [lib/net/formdata.ts:67](https://github.com/maiyunnet/kebab/blob/mas
9992
10026
 
9993
10027
  > **putString**(`key`, `val`): `void`
9994
10028
 
9995
- Defined in: [lib/net/formdata.ts:50](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L50)
10029
+ Defined in: [lib/net/formdata.ts:65](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L65)
9996
10030
 
9997
10031
  添加字符串
9998
10032
 
@@ -10029,11 +10063,11 @@ lib/net/formdata/index.md
10029
10063
 
10030
10064
  - [FormData](classes/FormData.md)
10031
10065
 
10032
- ## Interfaces
10066
+ ## Type Aliases
10033
10067
 
10034
- - [IItem](interfaces/IItem.md)
10068
+ - [IItem](type-aliases/IItem.md)
10035
10069
 
10036
- lib/net/formdata/interfaces/IItem.md
10070
+ lib/net/formdata/type-aliases/IItem.md
10037
10071
  ---
10038
10072
 
10039
10073
  [**Documents for @maiyunnet/kebab**](../../../../index.md)
@@ -10042,55 +10076,85 @@ lib/net/formdata/interfaces/IItem.md
10042
10076
 
10043
10077
  [Documents for @maiyunnet/kebab](../../../../index.md) / [lib/net/formdata](../index.md) / IItem
10044
10078
 
10045
- # Interface: IItem
10079
+ # Type Alias: IItem
10080
+
10081
+ > **IItem** = \{ `key`: `string`; `path`: `""`; `type`: `"string"`; `value`: `string`; \} \| \{ `key`: `string`; `path`: `string`; `type`: `"file"`; `value`: `string`; \} \| \{ `key`: `string`; `path`: `Buffer`; `type`: `"buffer"`; `value`: `string`; \}
10046
10082
 
10047
10083
  Defined in: [lib/net/formdata.ts:12](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L12)
10048
10084
 
10049
10085
  Item 对象
10050
10086
 
10051
- ## Properties
10087
+ ## Type Declaration
10052
10088
 
10053
- ### isFile
10089
+ \{ `key`: `string`; `path`: `""`; `type`: `"string"`; `value`: `string`; \}
10054
10090
 
10055
- > **isFile**: `boolean`
10091
+ ### key
10056
10092
 
10057
- Defined in: [lib/net/formdata.ts:15](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L15)
10093
+ > **key**: `string`
10058
10094
 
10059
- ***
10095
+ key 键
10060
10096
 
10061
- ### isString
10097
+ ### path
10062
10098
 
10063
- > **isString**: `boolean`
10099
+ > **path**: `""`
10064
10100
 
10065
- Defined in: [lib/net/formdata.ts:16](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L16)
10101
+ ### type
10066
10102
 
10067
- ***
10103
+ > **type**: `"string"`
10104
+
10105
+ ### value
10106
+
10107
+ > **value**: `string`
10108
+
10109
+ 字符串值
10110
+
10111
+ \{ `key`: `string`; `path`: `string`; `type`: `"file"`; `value`: `string`; \}
10068
10112
 
10069
10113
  ### key
10070
10114
 
10071
10115
  > **key**: `string`
10072
10116
 
10073
- Defined in: [lib/net/formdata.ts:14](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L14)
10074
-
10075
10117
  key 键
10076
10118
 
10077
- ***
10078
-
10079
10119
  ### path
10080
10120
 
10081
10121
  > **path**: `string`
10082
10122
 
10083
- Defined in: [lib/net/formdata.ts:19](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L19)
10123
+ 文件路径
10084
10124
 
10085
- ***
10125
+ ### type
10126
+
10127
+ > **type**: `"file"`
10086
10128
 
10087
10129
  ### value
10088
10130
 
10089
10131
  > **value**: `string`
10090
10132
 
10091
- Defined in: [lib/net/formdata.ts:18](https://github.com/maiyunnet/kebab/blob/master/lib/net/formdata.ts#L18)
10133
+ 文件名
10092
10134
 
10093
- 值或者文件名
10135
+ \{ `key`: `string`; `path`: `Buffer`; `type`: `"buffer"`; `value`: `string`; \}
10136
+
10137
+ ### key
10138
+
10139
+ > **key**: `string`
10140
+
10141
+ key 键
10142
+
10143
+ ### path
10144
+
10145
+ > **path**: `Buffer`
10146
+
10147
+ Buffer 数据
10148
+
10149
+ ### type
10150
+
10151
+ > **type**: `"buffer"`
10152
+
10153
+ ### value
10154
+
10155
+ > **value**: `string`
10156
+
10157
+ 文件名
10094
10158
 
10095
10159
  lib/net/functions/buildCookieQuery.md
10096
10160
  ---
@@ -10105,7 +10169,7 @@ lib/net/functions/buildCookieQuery.md
10105
10169
 
10106
10170
  > **buildCookieQuery**(`cookie`, `uri`): `string`
10107
10171
 
10108
- Defined in: [lib/net.ts:474](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L474)
10172
+ Defined in: [lib/net.ts:595](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L595)
10109
10173
 
10110
10174
  对象转换为 Cookie 拼接字符串(会自动筛掉不能发送的 cookie)
10111
10175
 
@@ -10142,7 +10206,7 @@ lib/net/functions/fetch.md
10142
10206
 
10143
10207
  Defined in: [lib/net.ts:131](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L131)
10144
10208
 
10145
- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误
10209
+ 发起一个完全兼容 fetch 的请求
10146
10210
 
10147
10211
  ## Parameters
10148
10212
 
@@ -10156,7 +10220,7 @@ Defined in: [lib/net.ts:131](https://github.com/maiyunnet/kebab/blob/master/lib/
10156
10220
 
10157
10221
  `RequestInit` & `object` = `{}`
10158
10222
 
10159
- 增加 mproxy
10223
+ 增加 mproxy、hosts
10160
10224
 
10161
10225
  ## Returns
10162
10226
 
@@ -10175,7 +10239,7 @@ lib/net/functions/filterHeaders.md
10175
10239
 
10176
10240
  > **filterHeaders**(`headers`, `res?`, `filter?`): `Record`\<`string`, `string` \| `string`[]\>
10177
10241
 
10178
- Defined in: [lib/net.ts:552](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L552)
10242
+ Defined in: [lib/net.ts:673](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L673)
10179
10243
 
10180
10244
  剔除不代理的 header,返回新的 header
10181
10245
 
@@ -10272,7 +10336,7 @@ lib/net/functions/getFormData.md
10272
10336
 
10273
10337
  > **getFormData**(): [`FormData`](../formdata/classes/FormData.md)
10274
10338
 
10275
- Defined in: [lib/net.ts:536](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L536)
10339
+ Defined in: [lib/net.ts:657](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L657)
10276
10340
 
10277
10341
  创建 FormData 对象
10278
10342
 
@@ -10293,7 +10357,7 @@ lib/net/functions/mproxy.md
10293
10357
 
10294
10358
  > **mproxy**(`ctr`, `auth`, `opt`): `Promise`\<`number`\>
10295
10359
 
10296
- Defined in: [lib/net.ts:588](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L588)
10360
+ Defined in: [lib/net.ts:709](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L709)
10297
10361
 
10298
10362
  正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址
10299
10363
  get: url, auth
@@ -10335,7 +10399,7 @@ lib/net/functions/mproxyData.md
10335
10399
 
10336
10400
  > **mproxyData**(`ctr`): `any`
10337
10401
 
10338
- Defined in: [lib/net.ts:637](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L637)
10402
+ Defined in: [lib/net.ts:758](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L758)
10339
10403
 
10340
10404
  获取 mproxy 的附加数据
10341
10405
 
@@ -10516,7 +10580,7 @@ lib/net/functions/request.md
10516
10580
 
10517
10581
  > **request**(`u`, `data?`, `opt?`): `Promise`\<[`Response`](../response/classes/Response.md)\>
10518
10582
 
10519
- Defined in: [lib/net.ts:160](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L160)
10583
+ Defined in: [lib/net.ts:281](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L281)
10520
10584
 
10521
10585
  发起一个请求
10522
10586
 
@@ -10553,7 +10617,7 @@ lib/net/functions/resetCookieSession.md
10553
10617
 
10554
10618
  > **resetCookieSession**(`cookie`): `void`
10555
10619
 
10556
- Defined in: [lib/net.ts:524](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L524)
10620
+ Defined in: [lib/net.ts:645](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L645)
10557
10621
 
10558
10622
  模拟重启浏览器后的状态
10559
10623
 
@@ -10582,7 +10646,7 @@ lib/net/functions/rproxy.md
10582
10646
 
10583
10647
  > **rproxy**(`ctr`, `route`, `opt`): `Promise`\<`boolean`\>
10584
10648
 
10585
- Defined in: [lib/net.ts:655](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L655)
10649
+ Defined in: [lib/net.ts:776](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L776)
10586
10650
 
10587
10651
  反向代理,注意提前处理不要自动处理 post 数据,将本服务器的某个路由反代到其他网址
10588
10652
 
@@ -10623,7 +10687,7 @@ lib/net/functions/setCookie.md
10623
10687
 
10624
10688
  > **setCookie**(`cookie`, `name`, `value`, `domain`, `opt`): `void`
10625
10689
 
10626
- Defined in: [lib/net.ts:336](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L336)
10690
+ Defined in: [lib/net.ts:457](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L457)
10627
10691
 
10628
10692
  对 cookie 对象进行操作
10629
10693
 
@@ -10729,7 +10793,7 @@ lib/net/interfaces/ICookie.md
10729
10793
 
10730
10794
  # Interface: ICookie
10731
10795
 
10732
- Defined in: [lib/net.ts:780](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L780)
10796
+ Defined in: [lib/net.ts:901](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L901)
10733
10797
 
10734
10798
  Net Cookie 对象
10735
10799
 
@@ -10739,7 +10803,7 @@ Net Cookie 对象
10739
10803
 
10740
10804
  > **domain**: `string`
10741
10805
 
10742
- Defined in: [lib/net.ts:786](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L786)
10806
+ Defined in: [lib/net.ts:907](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L907)
10743
10807
 
10744
10808
  ***
10745
10809
 
@@ -10747,7 +10811,7 @@ Defined in: [lib/net.ts:786](https://github.com/maiyunnet/kebab/blob/master/lib/
10747
10811
 
10748
10812
  > **exp**: `number`
10749
10813
 
10750
- Defined in: [lib/net.ts:784](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L784)
10814
+ Defined in: [lib/net.ts:905](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L905)
10751
10815
 
10752
10816
  有效期秒级时间戳
10753
10817
 
@@ -10757,7 +10821,7 @@ Defined in: [lib/net.ts:784](https://github.com/maiyunnet/kebab/blob/master/lib/
10757
10821
 
10758
10822
  > **httponly**: `boolean`
10759
10823
 
10760
- Defined in: [lib/net.ts:788](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L788)
10824
+ Defined in: [lib/net.ts:909](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L909)
10761
10825
 
10762
10826
  ***
10763
10827
 
@@ -10765,7 +10829,7 @@ Defined in: [lib/net.ts:788](https://github.com/maiyunnet/kebab/blob/master/lib/
10765
10829
 
10766
10830
  > **name**: `string`
10767
10831
 
10768
- Defined in: [lib/net.ts:781](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L781)
10832
+ Defined in: [lib/net.ts:902](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L902)
10769
10833
 
10770
10834
  ***
10771
10835
 
@@ -10773,7 +10837,7 @@ Defined in: [lib/net.ts:781](https://github.com/maiyunnet/kebab/blob/master/lib/
10773
10837
 
10774
10838
  > **path**: `string`
10775
10839
 
10776
- Defined in: [lib/net.ts:785](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L785)
10840
+ Defined in: [lib/net.ts:906](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L906)
10777
10841
 
10778
10842
  ***
10779
10843
 
@@ -10781,7 +10845,7 @@ Defined in: [lib/net.ts:785](https://github.com/maiyunnet/kebab/blob/master/lib/
10781
10845
 
10782
10846
  > **secure**: `boolean`
10783
10847
 
10784
- Defined in: [lib/net.ts:787](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L787)
10848
+ Defined in: [lib/net.ts:908](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L908)
10785
10849
 
10786
10850
  ***
10787
10851
 
@@ -10789,7 +10853,7 @@ Defined in: [lib/net.ts:787](https://github.com/maiyunnet/kebab/blob/master/lib/
10789
10853
 
10790
10854
  > **value**: `string`
10791
10855
 
10792
- Defined in: [lib/net.ts:782](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L782)
10856
+ Defined in: [lib/net.ts:903](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L903)
10793
10857
 
10794
10858
  lib/net/interfaces/IMproxyOptions.md
10795
10859
  ---
@@ -10802,7 +10866,7 @@ lib/net/interfaces/IMproxyOptions.md
10802
10866
 
10803
10867
  # Interface: IMproxyOptions
10804
10868
 
10805
- Defined in: [lib/net.ts:735](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L735)
10869
+ Defined in: [lib/net.ts:856](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L856)
10806
10870
 
10807
10871
  正向代理请求的传入参数选项
10808
10872
 
@@ -10812,7 +10876,7 @@ Defined in: [lib/net.ts:735](https://github.com/maiyunnet/kebab/blob/master/lib/
10812
10876
 
10813
10877
  > `optional` **filter**: (`h`) => `boolean`
10814
10878
 
10815
- Defined in: [lib/net.ts:744](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L744)
10879
+ Defined in: [lib/net.ts:865](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L865)
10816
10880
 
10817
10881
  过滤 header,返回 true 则留下
10818
10882
 
@@ -10832,7 +10896,7 @@ Defined in: [lib/net.ts:744](https://github.com/maiyunnet/kebab/blob/master/lib/
10832
10896
 
10833
10897
  > `optional` **follow**: `number`
10834
10898
 
10835
- Defined in: [lib/net.ts:738](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L738)
10899
+ Defined in: [lib/net.ts:859](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L859)
10836
10900
 
10837
10901
  ***
10838
10902
 
@@ -10840,7 +10904,7 @@ Defined in: [lib/net.ts:738](https://github.com/maiyunnet/kebab/blob/master/lib/
10840
10904
 
10841
10905
  > `optional` **headers**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
10842
10906
 
10843
- Defined in: [lib/net.ts:742](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L742)
10907
+ Defined in: [lib/net.ts:863](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L863)
10844
10908
 
10845
10909
  ***
10846
10910
 
@@ -10848,7 +10912,7 @@ Defined in: [lib/net.ts:742](https://github.com/maiyunnet/kebab/blob/master/lib/
10848
10912
 
10849
10913
  > `optional` **hosts**: `string` \| `Record`\<`string`, `string`\>
10850
10914
 
10851
- Defined in: [lib/net.ts:740](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L740)
10915
+ Defined in: [lib/net.ts:861](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L861)
10852
10916
 
10853
10917
  自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
10854
10918
 
@@ -10858,7 +10922,7 @@ Defined in: [lib/net.ts:740](https://github.com/maiyunnet/kebab/blob/master/lib/
10858
10922
 
10859
10923
  > `optional` **local**: `string`
10860
10924
 
10861
- Defined in: [lib/net.ts:741](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L741)
10925
+ Defined in: [lib/net.ts:862](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L862)
10862
10926
 
10863
10927
  ***
10864
10928
 
@@ -10866,7 +10930,7 @@ Defined in: [lib/net.ts:741](https://github.com/maiyunnet/kebab/blob/master/lib/
10866
10930
 
10867
10931
  > `optional` **reuse**: `string`
10868
10932
 
10869
- Defined in: [lib/net.ts:746](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L746)
10933
+ Defined in: [lib/net.ts:867](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L867)
10870
10934
 
10871
10935
  默认为 default
10872
10936
 
@@ -10876,7 +10940,7 @@ Defined in: [lib/net.ts:746](https://github.com/maiyunnet/kebab/blob/master/lib/
10876
10940
 
10877
10941
  > `optional` **timeout**: `number`
10878
10942
 
10879
- Defined in: [lib/net.ts:737](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L737)
10943
+ Defined in: [lib/net.ts:858](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L858)
10880
10944
 
10881
10945
  秒数
10882
10946
 
@@ -10891,7 +10955,7 @@ lib/net/interfaces/IRequestOptions.md
10891
10955
 
10892
10956
  # Interface: IRequestOptions
10893
10957
 
10894
- Defined in: [lib/net.ts:708](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L708)
10958
+ Defined in: [lib/net.ts:829](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L829)
10895
10959
 
10896
10960
  请求的传入参数选项
10897
10961
 
@@ -10901,7 +10965,7 @@ Defined in: [lib/net.ts:708](https://github.com/maiyunnet/kebab/blob/master/lib/
10901
10965
 
10902
10966
  > `optional` **cookie**: `Record`\<`string`, [`ICookie`](ICookie.md)\>
10903
10967
 
10904
- Defined in: [lib/net.ts:731](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L731)
10968
+ Defined in: [lib/net.ts:852](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L852)
10905
10969
 
10906
10970
  cookie 托管对象
10907
10971
 
@@ -10911,7 +10975,7 @@ cookie 托管对象
10911
10975
 
10912
10976
  > `optional` **follow**: `number`
10913
10977
 
10914
- Defined in: [lib/net.ts:714](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L714)
10978
+ Defined in: [lib/net.ts:835](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L835)
10915
10979
 
10916
10980
  追踪 location 次数,0 为不追踪,默认为 0
10917
10981
 
@@ -10921,7 +10985,7 @@ Defined in: [lib/net.ts:714](https://github.com/maiyunnet/kebab/blob/master/lib/
10921
10985
 
10922
10986
  > `optional` **headers**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
10923
10987
 
10924
- Defined in: [lib/net.ts:719](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L719)
10988
+ Defined in: [lib/net.ts:840](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L840)
10925
10989
 
10926
10990
  ***
10927
10991
 
@@ -10929,7 +10993,7 @@ Defined in: [lib/net.ts:719](https://github.com/maiyunnet/kebab/blob/master/lib/
10929
10993
 
10930
10994
  > `optional` **hosts**: `string` \| `Record`\<`string`, `string`\>
10931
10995
 
10932
- Defined in: [lib/net.ts:716](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L716)
10996
+ Defined in: [lib/net.ts:837](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L837)
10933
10997
 
10934
10998
  自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
10935
10999
 
@@ -10939,7 +11003,7 @@ Defined in: [lib/net.ts:716](https://github.com/maiyunnet/kebab/blob/master/lib/
10939
11003
 
10940
11004
  > `optional` **keep**: `boolean`
10941
11005
 
10942
- Defined in: [lib/net.ts:727](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L727)
11006
+ Defined in: [lib/net.ts:848](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L848)
10943
11007
 
10944
11008
  连接是否保持长连接(即是否允许复用),默认为 true
10945
11009
 
@@ -10949,7 +11013,7 @@ Defined in: [lib/net.ts:727](https://github.com/maiyunnet/kebab/blob/master/lib/
10949
11013
 
10950
11014
  > `optional` **local**: `string`
10951
11015
 
10952
- Defined in: [lib/net.ts:718](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L718)
11016
+ Defined in: [lib/net.ts:839](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L839)
10953
11017
 
10954
11018
  ***
10955
11019
 
@@ -10957,7 +11021,7 @@ Defined in: [lib/net.ts:718](https://github.com/maiyunnet/kebab/blob/master/lib/
10957
11021
 
10958
11022
  > `optional` **method**: `"GET"` \| `"POST"` \| `"PUT"` \| `"DELETE"` \| `"OPTIONS"`
10959
11023
 
10960
- Defined in: [lib/net.ts:709](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L709)
11024
+ Defined in: [lib/net.ts:830](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L830)
10961
11025
 
10962
11026
  ***
10963
11027
 
@@ -10965,7 +11029,7 @@ Defined in: [lib/net.ts:709](https://github.com/maiyunnet/kebab/blob/master/lib/
10965
11029
 
10966
11030
  > `optional` **mproxy**: `object`
10967
11031
 
10968
- Defined in: [lib/net.ts:721](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L721)
11032
+ Defined in: [lib/net.ts:842](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L842)
10969
11033
 
10970
11034
  正向 mproxy 代理,url 如 https://xxx/abc
10971
11035
 
@@ -10987,7 +11051,7 @@ Defined in: [lib/net.ts:721](https://github.com/maiyunnet/kebab/blob/master/lib/
10987
11051
 
10988
11052
  > `optional` **reuse**: `string`
10989
11053
 
10990
- Defined in: [lib/net.ts:729](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L729)
11054
+ Defined in: [lib/net.ts:850](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L850)
10991
11055
 
10992
11056
  复用池名,默认为 default
10993
11057
 
@@ -10997,7 +11061,7 @@ Defined in: [lib/net.ts:729](https://github.com/maiyunnet/kebab/blob/master/lib/
10997
11061
 
10998
11062
  > `optional` **save**: `string`
10999
11063
 
11000
- Defined in: [lib/net.ts:717](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L717)
11064
+ Defined in: [lib/net.ts:838](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L838)
11001
11065
 
11002
11066
  ***
11003
11067
 
@@ -11005,7 +11069,7 @@ Defined in: [lib/net.ts:717](https://github.com/maiyunnet/kebab/blob/master/lib/
11005
11069
 
11006
11070
  > `optional` **timeout**: `number`
11007
11071
 
11008
- Defined in: [lib/net.ts:712](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L712)
11072
+ Defined in: [lib/net.ts:833](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L833)
11009
11073
 
11010
11074
  秒数
11011
11075
 
@@ -11015,7 +11079,7 @@ Defined in: [lib/net.ts:712](https://github.com/maiyunnet/kebab/blob/master/lib/
11015
11079
 
11016
11080
  > `optional` **type**: `"form"` \| `"json"`
11017
11081
 
11018
- Defined in: [lib/net.ts:710](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L710)
11082
+ Defined in: [lib/net.ts:831](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L831)
11019
11083
 
11020
11084
  lib/net/interfaces/IRproxyOptions.md
11021
11085
  ---
@@ -11028,7 +11092,7 @@ lib/net/interfaces/IRproxyOptions.md
11028
11092
 
11029
11093
  # Interface: IRproxyOptions
11030
11094
 
11031
- Defined in: [lib/net.ts:750](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L750)
11095
+ Defined in: [lib/net.ts:871](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L871)
11032
11096
 
11033
11097
  反向代理请求的传入参数选项
11034
11098
 
@@ -11038,7 +11102,7 @@ Defined in: [lib/net.ts:750](https://github.com/maiyunnet/kebab/blob/master/lib/
11038
11102
 
11039
11103
  > `optional` **filter**: (`h`) => `boolean`
11040
11104
 
11041
- Defined in: [lib/net.ts:759](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L759)
11105
+ Defined in: [lib/net.ts:880](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L880)
11042
11106
 
11043
11107
  过滤 header,返回 true 则留下
11044
11108
 
@@ -11058,7 +11122,7 @@ Defined in: [lib/net.ts:759](https://github.com/maiyunnet/kebab/blob/master/lib/
11058
11122
 
11059
11123
  > `optional` **follow**: `number`
11060
11124
 
11061
- Defined in: [lib/net.ts:753](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L753)
11125
+ Defined in: [lib/net.ts:874](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L874)
11062
11126
 
11063
11127
  ***
11064
11128
 
@@ -11066,7 +11130,7 @@ Defined in: [lib/net.ts:753](https://github.com/maiyunnet/kebab/blob/master/lib/
11066
11130
 
11067
11131
  > `optional` **headers**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
11068
11132
 
11069
- Defined in: [lib/net.ts:757](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L757)
11133
+ Defined in: [lib/net.ts:878](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L878)
11070
11134
 
11071
11135
  ***
11072
11136
 
@@ -11074,7 +11138,7 @@ Defined in: [lib/net.ts:757](https://github.com/maiyunnet/kebab/blob/master/lib/
11074
11138
 
11075
11139
  > `optional` **hosts**: `string` \| `Record`\<`string`, `string`\>
11076
11140
 
11077
- Defined in: [lib/net.ts:755](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L755)
11141
+ Defined in: [lib/net.ts:876](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L876)
11078
11142
 
11079
11143
  自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
11080
11144
 
@@ -11084,7 +11148,7 @@ Defined in: [lib/net.ts:755](https://github.com/maiyunnet/kebab/blob/master/lib/
11084
11148
 
11085
11149
  > `optional` **local**: `string`
11086
11150
 
11087
- Defined in: [lib/net.ts:756](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L756)
11151
+ Defined in: [lib/net.ts:877](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L877)
11088
11152
 
11089
11153
  ***
11090
11154
 
@@ -11092,7 +11156,7 @@ Defined in: [lib/net.ts:756](https://github.com/maiyunnet/kebab/blob/master/lib/
11092
11156
 
11093
11157
  > `optional` **mproxy**: `object`
11094
11158
 
11095
- Defined in: [lib/net.ts:761](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L761)
11159
+ Defined in: [lib/net.ts:882](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L882)
11096
11160
 
11097
11161
  正向 mproxy 代理,url 如 https://xxx/abc
11098
11162
 
@@ -11114,7 +11178,7 @@ Defined in: [lib/net.ts:761](https://github.com/maiyunnet/kebab/blob/master/lib/
11114
11178
 
11115
11179
  > `optional` **reuse**: `string`
11116
11180
 
11117
- Defined in: [lib/net.ts:767](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L767)
11181
+ Defined in: [lib/net.ts:888](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L888)
11118
11182
 
11119
11183
  默认为 default
11120
11184
 
@@ -11124,7 +11188,7 @@ Defined in: [lib/net.ts:767](https://github.com/maiyunnet/kebab/blob/master/lib/
11124
11188
 
11125
11189
  > `optional` **timeout**: `number`
11126
11190
 
11127
- Defined in: [lib/net.ts:752](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L752)
11191
+ Defined in: [lib/net.ts:873](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L873)
11128
11192
 
11129
11193
  秒数
11130
11194
 
@@ -11585,7 +11649,7 @@ lib/net/type-aliases/THttpHeaders.md
11585
11649
 
11586
11650
  > **THttpHeaders** = `http.IncomingHttpHeaders` & `object`
11587
11651
 
11588
- Defined in: [lib/net.ts:772](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L772)
11652
+ Defined in: [lib/net.ts:893](https://github.com/maiyunnet/kebab/blob/master/lib/net.ts#L893)
11589
11653
 
11590
11654
  http headers
11591
11655
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "7.9.0";
8
+ export declare const VER = "7.10.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '7.9.0';
9
+ export const VER = '7.10.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
@@ -5,15 +5,30 @@
5
5
  */
6
6
  import * as stream from 'stream';
7
7
  /** --- Item 对象 --- */
8
- export interface IItem {
8
+ export type IItem = {
9
9
  /** --- key 键 --- */
10
10
  'key': string;
11
- 'isFile': boolean;
12
- 'isString': boolean;
13
- /** --- 值或者文件名 --- */
11
+ 'type': 'string';
12
+ /** --- 字符串值 --- */
14
13
  'value': string;
14
+ 'path': '';
15
+ } | {
16
+ /** --- key 键 --- */
17
+ 'key': string;
18
+ 'type': 'file';
19
+ /** --- 文件名 --- */
20
+ 'value': string;
21
+ /** --- 文件路径 --- */
15
22
  'path': string;
16
- }
23
+ } | {
24
+ /** --- key 键 --- */
25
+ 'key': string;
26
+ 'type': 'buffer';
27
+ /** --- 文件名 --- */
28
+ 'value': string;
29
+ /** --- Buffer 数据 --- */
30
+ 'path': Buffer;
31
+ };
17
32
  export declare class FormData extends stream.Readable {
18
33
  /** --- read 调用次数 --- */
19
34
  private _num;
@@ -42,6 +57,13 @@ export declare class FormData extends stream.Readable {
42
57
  * @param fname 可选,文件名
43
58
  */
44
59
  putFile(key: string, path: string, fname?: string): Promise<boolean>;
60
+ /**
61
+ * --- 添加 Buffer 数据 ---
62
+ * @param key 键
63
+ * @param buffer Buffer 数据
64
+ * @param fname 文件名
65
+ */
66
+ putBuffer(key: string, buffer: Buffer, fname: string): void;
45
67
  /**
46
68
  * --- 获取 boundary ---
47
69
  */
@@ -30,8 +30,7 @@ export class FormData extends stream.Readable {
30
30
  putString(key, val) {
31
31
  this._data.push({
32
32
  'key': key,
33
- 'isFile': false,
34
- 'isString': true,
33
+ 'type': 'string',
35
34
  'value': val,
36
35
  'path': ''
37
36
  });
@@ -55,8 +54,7 @@ export class FormData extends stream.Readable {
55
54
  }
56
55
  this._data.push({
57
56
  'key': key,
58
- 'isFile': true,
59
- 'isString': false,
57
+ 'type': 'file',
60
58
  'value': fname,
61
59
  'path': path
62
60
  });
@@ -65,6 +63,23 @@ export class FormData extends stream.Readable {
65
63
  mime.getMime(fname).length + stat.size + 2;
66
64
  return true;
67
65
  }
66
+ /**
67
+ * --- 添加 Buffer 数据 ---
68
+ * @param key 键
69
+ * @param buffer Buffer 数据
70
+ * @param fname 文件名
71
+ */
72
+ putBuffer(key, buffer, fname) {
73
+ this._data.push({
74
+ 'key': key,
75
+ 'type': 'buffer',
76
+ 'value': fname,
77
+ 'path': buffer
78
+ });
79
+ this._length += this._boundary.length +
80
+ 76 + Buffer.byteLength(key) + Buffer.byteLength(fname) +
81
+ mime.getMime(fname).length + buffer.byteLength + 2;
82
+ }
68
83
  /**
69
84
  * --- 获取 boundary ---
70
85
  */
@@ -107,7 +122,18 @@ export class FormData extends stream.Readable {
107
122
  this.push(push);
108
123
  return;
109
124
  }
110
- if (item.isString) {
125
+ if (item.type === 'buffer') {
126
+ // --- Buffer 数据 ---
127
+ const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"; filename="${item.value}"\r\nContent-Type: ${mime.getMime(item.value)}\r\n\r\n`;
128
+ this._sent += Buffer.byteLength(push);
129
+ this.push(push);
130
+ this._sent += item.path.byteLength;
131
+ this.push(item.path);
132
+ const pushEnd = '\r\n';
133
+ this._sent += Buffer.byteLength(pushEnd);
134
+ this.push(pushEnd);
135
+ }
136
+ else if (item.type === 'string') {
111
137
  // --- 字段 ---
112
138
  const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"\r\n\r\n${item.value}\r\n`;
113
139
  this._sent += Buffer.byteLength(push);
package/lib/net.d.ts CHANGED
@@ -48,9 +48,9 @@ export declare function postJson(u: string, data: kebab.Json[] | Record<string,
48
48
  */
49
49
  export declare function postJsonResponseJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<kebab.Json | null>;
50
50
  /**
51
- * --- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误 ---
51
+ * --- 发起一个完全兼容 fetch 的请求 ---
52
52
  * @param input 请求的 URL 或 Request 对象
53
- * @param init 增加 mproxy
53
+ * @param init 增加 mproxy、hosts
54
54
  */
55
55
  export declare function fetch(input: string | URL | Request, init?: RequestInit & {
56
56
  /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
@@ -59,6 +59,8 @@ export declare function fetch(input: string | URL | Request, init?: RequestInit
59
59
  'auth': string;
60
60
  'data'?: kebab.Json;
61
61
  };
62
+ /** --- 自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host --- */
63
+ 'hosts'?: Record<string, string> | string;
62
64
  }): Promise<Response>;
63
65
  /**
64
66
  * --- 发起一个请求 ---
package/lib/net.js CHANGED
@@ -97,23 +97,142 @@ export async function postJsonResponseJson(u, data, opt = {}) {
97
97
  return json;
98
98
  }
99
99
  /**
100
- * --- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误 ---
100
+ * --- 发起一个完全兼容 fetch 的请求 ---
101
101
  * @param input 请求的 URL 或 Request 对象
102
- * @param init 增加 mproxy
102
+ * @param init 增加 mproxy、hosts
103
103
  */
104
- export function fetch(input, init = {}) {
105
- const u = (input instanceof Request) ?
106
- input.url :
107
- input instanceof URL ? input.toString() : input;
108
- const uri = lText.parseUrl(u);
109
- /** --- 正向代理的地址 --- */
110
- const puri = init.mproxy ? lText.parseUrl(init.mproxy.url) : null;
111
- /** --- 定义请求 host --- */
112
- const hostname = (puri ? puri.hostname : uri.hostname) ?? '';
113
- if (!hostname) {
114
- throw new Error('Kebab TypeError: Hostname is empty');
104
+ export async function fetch(input, init = {}) {
105
+ // --- 解析 URL ---
106
+ let u;
107
+ let method = 'GET';
108
+ let headers = {};
109
+ let body;
110
+ // --- 处理 input 参数 ---
111
+ if (input instanceof Request) {
112
+ u = input.url;
113
+ method = input.method.toUpperCase();
114
+ for (const [key, value] of input.headers) {
115
+ headers[key.toLowerCase()] = value;
116
+ }
117
+ if (input.body) {
118
+ body = Buffer.from(await input.arrayBuffer());
119
+ }
120
+ }
121
+ else {
122
+ u = input instanceof URL ? input.toString() : input;
123
+ }
124
+ // --- 处理 init 参数 ---
125
+ if (init.method) {
126
+ method = init.method.toUpperCase();
127
+ }
128
+ // --- 处理 headers ---
129
+ if (init.headers) {
130
+ if (init.headers instanceof Headers) {
131
+ for (const [key, value] of init.headers) {
132
+ headers[key.toLowerCase()] = value;
133
+ }
134
+ }
135
+ else if (Array.isArray(init.headers)) {
136
+ for (const [key, value] of init.headers) {
137
+ headers[key.toLowerCase()] = value;
138
+ }
139
+ }
140
+ else {
141
+ for (const key in init.headers) {
142
+ headers[key.toLowerCase()] = init.headers[key];
143
+ }
144
+ }
145
+ }
146
+ // --- 处理 body ---
147
+ if (init.body !== undefined && init.body !== null) {
148
+ if (typeof init.body === 'string') {
149
+ body = init.body;
150
+ }
151
+ else if (init.body instanceof ArrayBuffer) {
152
+ body = Buffer.from(init.body);
153
+ }
154
+ else if (init.body instanceof URLSearchParams) {
155
+ body = init.body.toString();
156
+ headers['content-type'] ??= 'application/x-www-form-urlencoded';
157
+ }
158
+ else if (init.body instanceof Blob) {
159
+ body = Buffer.from(await init.body.arrayBuffer());
160
+ }
161
+ else if (init.body instanceof FormData) {
162
+ // --- 原生 FormData 转为框架 FormData ---
163
+ const fd = getFormData();
164
+ for (const [key, value] of init.body.entries()) {
165
+ if (typeof value === 'string') {
166
+ fd.putString(key, value);
167
+ }
168
+ else {
169
+ fd.putBuffer(key, Buffer.from(await value.arrayBuffer()), value.name);
170
+ }
171
+ }
172
+ body = fd;
173
+ headers['content-type'] = 'multipart/form-data; boundary=' + fd.getBoundary();
174
+ headers['content-length'] = fd.getLength().toString();
175
+ }
176
+ else if (init.body instanceof ReadableStream) {
177
+ body = stream.Readable.fromWeb(init.body);
178
+ }
179
+ else if (ArrayBuffer.isView(init.body)) {
180
+ // --- ArrayBufferView (Uint8Array 等 TypedArray) ---
181
+ body = Buffer.from(init.body.buffer, init.body.byteOffset, init.body.byteLength);
182
+ }
115
183
  }
116
- return global.fetch(init.mproxy ? getMproxyUrl(u, init.mproxy) : u, init);
184
+ // --- 构建请求选项 ---
185
+ const opt = {
186
+ 'method': method,
187
+ 'headers': headers,
188
+ 'hosts': init.hosts,
189
+ 'mproxy': init.mproxy,
190
+ 'follow': init.redirect === 'follow' ? 10 : 0,
191
+ };
192
+ // --- 检查是否已中止(注意:请求发起后无法中止) ---
193
+ if (init.signal?.aborted) {
194
+ return new Response(null, {
195
+ 'status': 0,
196
+ 'statusText': 'Aborted',
197
+ });
198
+ }
199
+ // --- 发起请求 ---
200
+ const res = await request(u, body, opt);
201
+ // --- 转换为原生 Response ---
202
+ const resStream = res.getStream();
203
+ const resHeaders = new Headers();
204
+ if (res.headers) {
205
+ for (const key in res.headers) {
206
+ if (key.startsWith('http-')) {
207
+ continue;
208
+ }
209
+ const value = res.headers[key];
210
+ if (value === undefined) {
211
+ continue;
212
+ }
213
+ if (Array.isArray(value)) {
214
+ for (const v of value) {
215
+ resHeaders.append(key, v);
216
+ }
217
+ }
218
+ else {
219
+ resHeaders.set(key, value.toString());
220
+ }
221
+ }
222
+ }
223
+ const status = res.headers?.['http-code'] ?? (res.error ? 0 : 200);
224
+ if (res.error || !resStream) {
225
+ return new Response(null, {
226
+ 'status': status,
227
+ 'statusText': res.error?.message ?? 'Unknown Error',
228
+ 'headers': resHeaders,
229
+ });
230
+ }
231
+ return new Response(stream.Readable.toWeb(resStream), {
232
+ 'status': status,
233
+ 'statusText': '',
234
+ 'headers': resHeaders,
235
+ });
117
236
  }
118
237
  /**
119
238
  * --- 发起一个请求 ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "7.9.0",
3
+ "version": "7.10.0",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -1,8 +0,0 @@
1
- import * as sCtr from '#kebab/sys/ctr.js';
2
- export default class extends sCtr.Ctr {
3
- /**
4
- * --- Agent 示例接口 ---
5
- * --- 访问:/agent?q=上海天气怎么样? ---
6
- */
7
- index(): Promise<string>;
8
- }
@@ -1,68 +0,0 @@
1
- import * as sCtr from '#kebab/sys/ctr.js';
2
- import * as lAi from '#kebab/lib/ai.js';
3
- import * as lFs from '#kebab/lib/fs.js';
4
- import * as lText from '#kebab/lib/text.js';
5
- /** --- Skill 导入 --- */
6
- import sWeather from '../skill/weather.js';
7
- export default class extends sCtr.Ctr {
8
- /**
9
- * --- Agent 示例接口 ---
10
- * --- 访问:/agent?q=上海天气怎么样? ---
11
- */
12
- async index() {
13
- // --- 1. 获取用户问题 ---
14
- const userPrompt = this._get['q'] ?? '你好';
15
- // --- 2. 加载系统提示词 ---
16
- const systemPrompt = await lFs.getContent(`${this._config.const.rootPath}www/example/prompt/agent.txt`, 'utf8') ?? '';
17
- // --- 3. 初始化 AI ---
18
- const ai = lAi.get(this, {
19
- 'service': lAi.ESERVICE.ALICN,
20
- });
21
- // --- 4. 准备消息 ---
22
- const messages = [
23
- { 'role': 'system', 'content': systemPrompt },
24
- { 'role': 'user', 'content': userPrompt },
25
- ];
26
- // --- 5. 第一次对话,传入 Skills 定义 ---
27
- const res = await ai.chat({
28
- 'model': 'qwen-plus',
29
- 'messages': messages,
30
- 'tools': [sWeather.definition],
31
- });
32
- if (!res) {
33
- return '系统错误';
34
- }
35
- const message = res.choices[0].message;
36
- // --- 6. 如果 AI 决定调用工具 ---
37
- if (message.tool_calls && message.tool_calls.length > 0) {
38
- messages.push(message);
39
- for (const toolCall of message.tool_calls) {
40
- if (toolCall.function.name === 'get_weather') {
41
- // --- 解析参数并执行 ---
42
- const args = lText.parseJson(toolCall.function.arguments);
43
- if (args === false) {
44
- continue;
45
- }
46
- const result = await sWeather.execute(args);
47
- // --- 将结果反馈给消息流 ---
48
- messages.push({
49
- 'role': 'tool',
50
- 'tool_call_id': toolCall.id,
51
- 'name': 'get_weather',
52
- 'content': result,
53
- });
54
- }
55
- }
56
- // --- 7. 第二次对话,获取最终文本回复 ---
57
- const finalRes = await ai.chat({
58
- 'model': 'qwen-plus',
59
- 'messages': messages,
60
- });
61
- if (finalRes) {
62
- return finalRes.choices[0].message.content ?? '未能生成回复';
63
- }
64
- }
65
- // --- 如果不需要工具调用,直接返回内容 ---
66
- return message.content ?? '未能生成回复';
67
- }
68
- }