@nsnanocat/util 2.2.0 → 2.2.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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/polyfill/fetch.mjs +19 -17
package/package.json CHANGED
@@ -35,11 +35,12 @@
35
35
  "types"
36
36
  ],
37
37
  "devDependencies": {
38
- "typescript": "^5.6.3"
38
+ "@biomejs/biome": "2.4.6",
39
+ "typescript": "^5.9.3"
39
40
  },
40
41
  "publishConfig": {
41
42
  "registry": "https://registry.npmjs.org/",
42
43
  "access": "public"
43
44
  },
44
- "version": "2.2.0"
45
+ "version": "2.2.3"
45
46
  }
@@ -111,6 +111,25 @@ export async function fetch(resource, options = {}) {
111
111
  // Convert to seconds first and treat values above 500 as milliseconds.
112
112
  if (resource.timeout > 500) resource.timeout = Math.round(resource.timeout / 1000);
113
113
  }
114
+ // 某些平台要求毫秒级超时,进行二次换算。
115
+ // Some platforms expect timeout in milliseconds, so convert again.
116
+ if (resource.timeout) {
117
+ switch ($app) {
118
+ case "Loon":
119
+ case "Quantumult X":
120
+ case "Node.js":
121
+ // 这些平台要求毫秒,因此把秒重新换算为毫秒。
122
+ // These platforms expect milliseconds, so convert seconds back to milliseconds.
123
+ resource.timeout = resource.timeout * 1000;
124
+ break;
125
+ case "Shadowrocket":
126
+ case "Stash":
127
+ case "Egern":
128
+ case "Surge":
129
+ default:
130
+ break;
131
+ }
132
+ }
114
133
  // 根据当前平台选择请求实现。
115
134
  // Select the request engine for the current platform.
116
135
  switch ($app) {
@@ -122,23 +141,6 @@ export async function fetch(resource, options = {}) {
122
141
  default:
123
142
  // 转换通用请求参数到 `$httpClient` 语义。
124
143
  // Map shared request fields to `$httpClient` semantics.
125
- if (resource.timeout) {
126
- switch ($app) {
127
- case "Loon":
128
- case "Quantumult X":
129
- case "Node.js":
130
- // 这些平台要求毫秒,因此把秒重新换算为毫秒。
131
- // These platforms expect milliseconds, so convert seconds back to milliseconds.
132
- resource.timeout = resource.timeout * 1000;
133
- break;
134
- case "Shadowrocket":
135
- case "Stash":
136
- case "Egern":
137
- case "Surge":
138
- default:
139
- break;
140
- }
141
- }
142
144
  if (resource.policy) {
143
145
  switch ($app) {
144
146
  case "Loon":