com.jimuwd.xian.registry-proxy 1.0.40 → 1.0.41
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/index.js +2 -23
- package/package.json +1 -1
- package/src/index.ts +2 -24
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import fetch from 'node-fetch';
|
|
|
7
7
|
import { homedir } from 'os';
|
|
8
8
|
import { join, resolve } from 'path';
|
|
9
9
|
import { URL } from 'url';
|
|
10
|
-
import { Readable } from "node:stream";
|
|
11
10
|
import { pipeline } from "node:stream/promises";
|
|
12
11
|
const { readFile, writeFile } = fsPromises;
|
|
13
12
|
class ConcurrencyLimiter {
|
|
@@ -199,7 +198,7 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
|
-
res.writeHead(
|
|
201
|
+
res.writeHead(response.status, { "content-type": contentType });
|
|
203
202
|
res.end(JSON.stringify(data));
|
|
204
203
|
}
|
|
205
204
|
else {
|
|
@@ -209,27 +208,7 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
209
208
|
console.error(`Empty response body from ${targetUrl}`);
|
|
210
209
|
}
|
|
211
210
|
else {
|
|
212
|
-
|
|
213
|
-
if (typeof Readable.fromWeb === 'function') {
|
|
214
|
-
// Node.js 17+ 标准方式
|
|
215
|
-
nodeStream = Readable.fromWeb(response.body);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
// Node.js 16 及以下版本的兼容方案
|
|
219
|
-
const { PassThrough } = await import('stream');
|
|
220
|
-
const passThrough = new PassThrough();
|
|
221
|
-
const reader = response.body.getReader();
|
|
222
|
-
const pump = async () => {
|
|
223
|
-
const { done, value } = await reader.read();
|
|
224
|
-
if (done)
|
|
225
|
-
return passThrough.end();
|
|
226
|
-
passThrough.write(value);
|
|
227
|
-
await pump();
|
|
228
|
-
};
|
|
229
|
-
pump().catch(err => passThrough.destroy(err));
|
|
230
|
-
nodeStream = passThrough;
|
|
231
|
-
}
|
|
232
|
-
await pipeline(nodeStream, res);
|
|
211
|
+
await pipeline(response.body, res);
|
|
233
212
|
}
|
|
234
213
|
}
|
|
235
214
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import fetch, {Response} from 'node-fetch';
|
|
|
8
8
|
import {homedir} from 'os';
|
|
9
9
|
import {join, resolve} from 'path';
|
|
10
10
|
import {URL} from 'url';
|
|
11
|
-
import {Readable} from "node:stream";
|
|
12
11
|
import {pipeline} from "node:stream/promises";
|
|
13
12
|
|
|
14
13
|
const {readFile, writeFile} = fsPromises;
|
|
@@ -266,7 +265,7 @@ async function writeSuccessfulResponse(
|
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
|
-
res.writeHead(
|
|
268
|
+
res.writeHead(response.status, {"content-type": contentType});
|
|
270
269
|
res.end(JSON.stringify(data));
|
|
271
270
|
} else {
|
|
272
271
|
// 二进制流处理
|
|
@@ -274,28 +273,7 @@ async function writeSuccessfulResponse(
|
|
|
274
273
|
if (!response.body) {
|
|
275
274
|
console.error(`Empty response body from ${targetUrl}`);
|
|
276
275
|
} else {
|
|
277
|
-
|
|
278
|
-
if (typeof Readable.fromWeb === 'function') {
|
|
279
|
-
// Node.js 17+ 标准方式
|
|
280
|
-
nodeStream = Readable.fromWeb(response.body as any);
|
|
281
|
-
} else {
|
|
282
|
-
// Node.js 16 及以下版本的兼容方案
|
|
283
|
-
const {PassThrough} = await import('stream');
|
|
284
|
-
const passThrough = new PassThrough();
|
|
285
|
-
const reader = (response.body as any).getReader();
|
|
286
|
-
|
|
287
|
-
const pump = async () => {
|
|
288
|
-
const {done, value} = await reader.read();
|
|
289
|
-
if (done) return passThrough.end();
|
|
290
|
-
passThrough.write(value);
|
|
291
|
-
await pump();
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
pump().catch(err => passThrough.destroy(err));
|
|
295
|
-
nodeStream = passThrough;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
await pipeline(nodeStream, res);
|
|
276
|
+
await pipeline(response.body, res);
|
|
299
277
|
}
|
|
300
278
|
}
|
|
301
279
|
} catch (err) {
|