@e-mc/request 0.12.8 → 0.12.10
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/README.md +6 -6
- package/index.js +84 -69
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.10/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -40,9 +40,9 @@ interface IRequest extends IModule {
|
|
|
40
40
|
headersOn(name: string | string[], callback: HeadersOnCallback): void;
|
|
41
41
|
headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
|
|
42
42
|
headersOf(uri: string): OutgoingHttpHeaders | undefined;
|
|
43
|
-
aria2c(uri: string | URL, pathname: string): Promise<string[]>;
|
|
43
|
+
aria2c(uri: string | URL, pathname: string | URL): Promise<string[]>;
|
|
44
44
|
aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
|
|
45
|
-
rclone(uri: string | URL, pathname: string): Promise<string[]>;
|
|
45
|
+
rclone(uri: string | URL, pathname: string | URL): Promise<string[]>;
|
|
46
46
|
rclone(uri: string | URL, options?: RcloneOptions): Promise<string[]>;
|
|
47
47
|
json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
|
|
48
48
|
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
@@ -255,9 +255,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
255
255
|
|
|
256
256
|
## References
|
|
257
257
|
|
|
258
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
259
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
260
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
258
|
+
- https://www.unpkg.com/@e-mc/types@0.12.10/lib/http.d.ts
|
|
259
|
+
- https://www.unpkg.com/@e-mc/types@0.12.10/lib/request.d.ts
|
|
260
|
+
- https://www.unpkg.com/@e-mc/types@0.12.10/lib/settings.d.ts
|
|
261
261
|
|
|
262
262
|
* https://www.npmjs.com/package/@types/node
|
|
263
263
|
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const qs = require("node:querystring");
|
|
|
14
14
|
const combined = require("combined-stream");
|
|
15
15
|
const pm = require("picomatch");
|
|
16
16
|
const which = require("which");
|
|
17
|
+
const node_url_1 = require("node:url");
|
|
17
18
|
const types_1 = require("@e-mc/types");
|
|
18
19
|
const module_1 = require("@e-mc/module");
|
|
19
20
|
const util_1 = require("@e-mc/request/util");
|
|
@@ -391,68 +392,8 @@ function setBinExec(settings, target) {
|
|
|
391
392
|
target.EXEC_GID = (gid = (0, util_1.asInt)(gid)) >= 0 ? gid : undefined;
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
|
-
function parseBinOpts(instance, options, ignore, skip, doubleQuote) {
|
|
395
|
-
let pathname = options.pathname, binOpts;
|
|
396
|
-
if (!(0, types_1.isString)(pathname)) {
|
|
397
|
-
if (!instance.host) {
|
|
398
|
-
return [];
|
|
399
|
-
}
|
|
400
|
-
pathname = process.cwd();
|
|
401
|
-
}
|
|
402
|
-
if ((0, types_1.isArray)(options.binOpts)) {
|
|
403
|
-
let next = false;
|
|
404
|
-
binOpts = options.binOpts.filter(opt => !((0, types_1.isString)(opt) && /^-[a-z].*$/i.test(opt.trim()))).map((opt) => {
|
|
405
|
-
if (next) {
|
|
406
|
-
if (!module_1.asString(opt).startsWith('--')) {
|
|
407
|
-
return [];
|
|
408
|
-
}
|
|
409
|
-
next = false;
|
|
410
|
-
}
|
|
411
|
-
switch (typeof opt) {
|
|
412
|
-
case 'string': {
|
|
413
|
-
const value = opt.trim();
|
|
414
|
-
if (value.startsWith('--')) {
|
|
415
|
-
const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)$/s.exec(value);
|
|
416
|
-
if (match) {
|
|
417
|
-
if (ignore.includes(match[1])) {
|
|
418
|
-
return [];
|
|
419
|
-
}
|
|
420
|
-
if (skip.includes(match[1])) {
|
|
421
|
-
if (!match[2]) {
|
|
422
|
-
next = true;
|
|
423
|
-
}
|
|
424
|
-
return [];
|
|
425
|
-
}
|
|
426
|
-
switch (match[1]) {
|
|
427
|
-
case '--version':
|
|
428
|
-
case '--help':
|
|
429
|
-
return [];
|
|
430
|
-
default:
|
|
431
|
-
return match[3] ? [match[1] + '=' + (0, types_1.sanitizeArgs)(match[3], doubleQuote)] : [match[1]];
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
else if (value) {
|
|
436
|
-
return [(0, types_1.sanitizeArgs)(value, doubleQuote)];
|
|
437
|
-
}
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
case 'number':
|
|
441
|
-
case 'boolean':
|
|
442
|
-
return [opt.toString()];
|
|
443
|
-
default:
|
|
444
|
-
if ((0, types_1.isArray)(opt)) {
|
|
445
|
-
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item, doubleQuote));
|
|
446
|
-
}
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
return [];
|
|
450
|
-
}).flat();
|
|
451
|
-
}
|
|
452
|
-
return [pathname, (0, util_1.parseOutgoingHeaders)(options.headers), binOpts];
|
|
453
|
-
}
|
|
454
395
|
function checkBinTarget(instance, name, uri, pathname, command, binOpts) {
|
|
455
|
-
if (!
|
|
396
|
+
if (!pathname) {
|
|
456
397
|
throw (0, types_1.errorMessage)(name, "Invalid parameters", 'pathname');
|
|
457
398
|
}
|
|
458
399
|
pathname = path.resolve(pathname);
|
|
@@ -644,7 +585,7 @@ class Request extends module_1 {
|
|
|
644
585
|
else if (proxy === false) {
|
|
645
586
|
ARIA2.PROXY = {};
|
|
646
587
|
}
|
|
647
|
-
if (no_proxy === ''
|
|
588
|
+
if (typeof no_proxy === 'string') {
|
|
648
589
|
ARIA2.NO_PROXY = no_proxy;
|
|
649
590
|
}
|
|
650
591
|
if (conf_path === '' || (0, types_1.isString)(conf_path) && this.isPath(conf_path = path.resolve(conf_path))) {
|
|
@@ -855,7 +796,7 @@ class Request extends module_1 {
|
|
|
855
796
|
break;
|
|
856
797
|
}
|
|
857
798
|
if (expires !== undefined) {
|
|
858
|
-
if (
|
|
799
|
+
if ((0, types_1.isString)(expires)) {
|
|
859
800
|
expires = (0, types_1.parseExpires)(expires);
|
|
860
801
|
}
|
|
861
802
|
if (expires >= 0) {
|
|
@@ -1104,8 +1045,12 @@ class Request extends module_1 {
|
|
|
1104
1045
|
}
|
|
1105
1046
|
break;
|
|
1106
1047
|
case 'readExpect':
|
|
1107
|
-
|
|
1108
|
-
|
|
1048
|
+
switch (value) {
|
|
1049
|
+
case 'string':
|
|
1050
|
+
case 'always':
|
|
1051
|
+
case 'none':
|
|
1052
|
+
this[name] = value;
|
|
1053
|
+
break;
|
|
1109
1054
|
}
|
|
1110
1055
|
break;
|
|
1111
1056
|
}
|
|
@@ -1280,12 +1225,15 @@ class Request extends module_1 {
|
|
|
1280
1225
|
return Promise.reject((0, types_1.errorMessage)("aria2", "Binary not found"));
|
|
1281
1226
|
}
|
|
1282
1227
|
let pathname, headers, binOpts, signal, silent;
|
|
1283
|
-
if (
|
|
1228
|
+
if (typeof options === 'string') {
|
|
1284
1229
|
pathname = options;
|
|
1285
1230
|
}
|
|
1231
|
+
else if (options instanceof URL) {
|
|
1232
|
+
pathname = (0, node_url_1.fileURLToPath)(options);
|
|
1233
|
+
}
|
|
1286
1234
|
else {
|
|
1287
1235
|
({ signal, silent } = options);
|
|
1288
|
-
|
|
1236
|
+
({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file'], options.shellExpansion));
|
|
1289
1237
|
}
|
|
1290
1238
|
try {
|
|
1291
1239
|
if (typeof uri === 'string' && module_1.isURL(uri)) {
|
|
@@ -1537,13 +1485,17 @@ class Request extends module_1 {
|
|
|
1537
1485
|
}
|
|
1538
1486
|
uri = uri.toString();
|
|
1539
1487
|
let pathname, headers, binOpts, silent;
|
|
1540
|
-
if (
|
|
1488
|
+
if (typeof options === 'string') {
|
|
1541
1489
|
pathname = options;
|
|
1542
1490
|
options = {};
|
|
1543
1491
|
}
|
|
1492
|
+
else if (options instanceof URL) {
|
|
1493
|
+
pathname = (0, node_url_1.fileURLToPath)(options);
|
|
1494
|
+
options = {};
|
|
1495
|
+
}
|
|
1544
1496
|
else {
|
|
1545
1497
|
silent = options.silent;
|
|
1546
|
-
|
|
1498
|
+
({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--interactive', '--dry-run'], ['–name-transform', '--partial-suffix', '--verbose'], options.shellExpansion));
|
|
1547
1499
|
}
|
|
1548
1500
|
const command = options.command || 'copy';
|
|
1549
1501
|
let source;
|
|
@@ -2423,6 +2375,69 @@ class Request extends module_1 {
|
|
|
2423
2375
|
}
|
|
2424
2376
|
request.destroy(reason);
|
|
2425
2377
|
}
|
|
2378
|
+
parseBinOpts(options, ignore, skip, doubleQuote = false) {
|
|
2379
|
+
let pathname = options.pathname, binOpts;
|
|
2380
|
+
if (pathname instanceof URL) {
|
|
2381
|
+
pathname = (0, node_url_1.fileURLToPath)(pathname);
|
|
2382
|
+
}
|
|
2383
|
+
else if (!(0, types_1.isString)(pathname)) {
|
|
2384
|
+
if (!this.host) {
|
|
2385
|
+
return {};
|
|
2386
|
+
}
|
|
2387
|
+
pathname = process.cwd();
|
|
2388
|
+
}
|
|
2389
|
+
if ((0, types_1.isArray)(options.binOpts)) {
|
|
2390
|
+
let next = false;
|
|
2391
|
+
binOpts = options.binOpts.filter((opt) => !((0, types_1.isString)(opt) && /^-[a-z].*$/i.test(opt.trim()))).map((opt) => {
|
|
2392
|
+
if (next) {
|
|
2393
|
+
if (!module_1.asString(opt).startsWith('--')) {
|
|
2394
|
+
return [];
|
|
2395
|
+
}
|
|
2396
|
+
next = false;
|
|
2397
|
+
}
|
|
2398
|
+
switch (typeof opt) {
|
|
2399
|
+
case 'string': {
|
|
2400
|
+
const value = opt.trim();
|
|
2401
|
+
if (value.startsWith('--')) {
|
|
2402
|
+
const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)$/s.exec(value);
|
|
2403
|
+
if (match) {
|
|
2404
|
+
if (ignore.includes(match[1])) {
|
|
2405
|
+
return [];
|
|
2406
|
+
}
|
|
2407
|
+
if (skip.includes(match[1])) {
|
|
2408
|
+
if (!match[2]) {
|
|
2409
|
+
next = true;
|
|
2410
|
+
}
|
|
2411
|
+
return [];
|
|
2412
|
+
}
|
|
2413
|
+
switch (match[1]) {
|
|
2414
|
+
case '--version':
|
|
2415
|
+
case '--help':
|
|
2416
|
+
return [];
|
|
2417
|
+
default:
|
|
2418
|
+
return match[3] ? [match[1] + '=' + (0, types_1.sanitizeArgs)(match[3], doubleQuote)] : [match[1]];
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
else if (value) {
|
|
2423
|
+
return [(0, types_1.sanitizeArgs)(value, doubleQuote)];
|
|
2424
|
+
}
|
|
2425
|
+
break;
|
|
2426
|
+
}
|
|
2427
|
+
case 'number':
|
|
2428
|
+
case 'boolean':
|
|
2429
|
+
return [opt.toString()];
|
|
2430
|
+
default:
|
|
2431
|
+
if ((0, types_1.isArray)(opt)) {
|
|
2432
|
+
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item, doubleQuote));
|
|
2433
|
+
}
|
|
2434
|
+
break;
|
|
2435
|
+
}
|
|
2436
|
+
return [];
|
|
2437
|
+
}).flat();
|
|
2438
|
+
}
|
|
2439
|
+
return { pathname, headers: (0, util_1.parseOutgoingHeaders)(options.headers), binOpts };
|
|
2440
|
+
}
|
|
2426
2441
|
set adapter(value) {
|
|
2427
2442
|
if (isConstructor(value) && value.prototype instanceof adapter_1) {
|
|
2428
2443
|
this.#adapter = value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.10",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/module": "0.12.
|
|
23
|
-
"@e-mc/types": "0.12.
|
|
22
|
+
"@e-mc/module": "0.12.10",
|
|
23
|
+
"@e-mc/types": "0.12.10",
|
|
24
24
|
"combined-stream": "^1.0.8",
|
|
25
25
|
"js-yaml": "^4.1.0",
|
|
26
26
|
"picomatch": "^4.0.3",
|