@e-mc/request 0.12.1 → 0.12.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.
- package/README.md +8 -6
- package/index.js +14 -15
- 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.2/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -42,8 +42,8 @@ interface IRequest extends IModule {
|
|
|
42
42
|
headersOf(uri: string): OutgoingHttpHeaders | undefined;
|
|
43
43
|
aria2c(uri: string | URL, pathname: string): Promise<string[]>;
|
|
44
44
|
aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
|
|
45
|
-
rclone(uri: string, pathname: string): Promise<string[]>;
|
|
46
|
-
rclone(uri: string, options?: RcloneOptions): Promise<string[]>;
|
|
45
|
+
rclone(uri: string | URL, pathname: string): Promise<string[]>;
|
|
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>;
|
|
49
49
|
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
@@ -81,7 +81,9 @@ interface RequestConstructor extends ModuleConstructor {
|
|
|
81
81
|
defineHttpAgent(options: HttpAgentSettings): void;
|
|
82
82
|
defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
|
|
83
83
|
defineHttpAdapter(module: unknown): void;
|
|
84
|
+
isRclone(value: string | URL): boolean;
|
|
84
85
|
getAria2Path(): string;
|
|
86
|
+
getRclonePath(): string;
|
|
85
87
|
readonly prototype: IRequest;
|
|
86
88
|
new(module?: RequestModule): IRequest;
|
|
87
89
|
}
|
|
@@ -253,9 +255,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
253
255
|
|
|
254
256
|
## References
|
|
255
257
|
|
|
256
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
257
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
258
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
258
|
+
- https://www.unpkg.com/@e-mc/types@0.12.2/lib/http.d.ts
|
|
259
|
+
- https://www.unpkg.com/@e-mc/types@0.12.2/lib/request.d.ts
|
|
260
|
+
- https://www.unpkg.com/@e-mc/types@0.12.2/lib/settings.d.ts
|
|
259
261
|
|
|
260
262
|
* https://www.npmjs.com/package/@types/node
|
|
261
263
|
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const SUPPORTED_NODE20 = (0, types_1.supported)(20);
|
|
|
24
24
|
const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) && typeof zlib.createZstdDecompress === 'function';
|
|
25
25
|
const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
|
|
26
26
|
const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
|
|
27
|
+
const REGEXP_RCLONE = /^rclone:\?/i;
|
|
27
28
|
const HTTP = {
|
|
28
29
|
HOST: {},
|
|
29
30
|
HEADERS: {},
|
|
@@ -390,7 +391,7 @@ function setBinExec(settings, target) {
|
|
|
390
391
|
target.EXEC_GID = (gid = (0, util_1.asInt)(gid)) >= 0 ? gid : undefined;
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
|
-
function parseBinOpts(instance, options, ignore, skip) {
|
|
394
|
+
function parseBinOpts(instance, options, ignore, skip, doubleQuote) {
|
|
394
395
|
let pathname = options.pathname, binOpts;
|
|
395
396
|
if (!(0, types_1.isString)(pathname)) {
|
|
396
397
|
if (!instance.host) {
|
|
@@ -427,12 +428,12 @@ function parseBinOpts(instance, options, ignore, skip) {
|
|
|
427
428
|
case '--help':
|
|
428
429
|
return [];
|
|
429
430
|
default:
|
|
430
|
-
return match[3] ? [match[1]
|
|
431
|
+
return match[3] ? [match[1] + '=' + (0, types_1.sanitizeArgs)(match[3], doubleQuote)] : [match[1]];
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
else if (value) {
|
|
435
|
-
return [(0, types_1.sanitizeArgs)(value)];
|
|
436
|
+
return [(0, types_1.sanitizeArgs)(value, doubleQuote)];
|
|
436
437
|
}
|
|
437
438
|
break;
|
|
438
439
|
}
|
|
@@ -441,7 +442,7 @@ function parseBinOpts(instance, options, ignore, skip) {
|
|
|
441
442
|
return [opt.toString()];
|
|
442
443
|
default:
|
|
443
444
|
if ((0, types_1.isArray)(opt)) {
|
|
444
|
-
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item));
|
|
445
|
+
return opt.filter(item => (0, types_1.isString)(item)).map(item => (0, types_1.sanitizeArgs)(item, doubleQuote));
|
|
445
446
|
}
|
|
446
447
|
break;
|
|
447
448
|
}
|
|
@@ -872,6 +873,9 @@ class Request extends module_1 {
|
|
|
872
873
|
HTTP_ADAPTER = module;
|
|
873
874
|
}
|
|
874
875
|
}
|
|
876
|
+
static isRclone(value) {
|
|
877
|
+
return REGEXP_RCLONE.test(value.toString());
|
|
878
|
+
}
|
|
875
879
|
static getAria2Path() {
|
|
876
880
|
return ARIA2.BIN;
|
|
877
881
|
}
|
|
@@ -1280,7 +1284,7 @@ class Request extends module_1 {
|
|
|
1280
1284
|
}
|
|
1281
1285
|
else {
|
|
1282
1286
|
({ signal, silent } = options);
|
|
1283
|
-
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--daemon'], ['--input-file']);
|
|
1287
|
+
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--daemon'], ['--input-file'], options.shellExpansion);
|
|
1284
1288
|
}
|
|
1285
1289
|
try {
|
|
1286
1290
|
if (typeof uri === 'string' && module_1.isURL(uri)) {
|
|
@@ -1427,7 +1431,7 @@ class Request extends module_1 {
|
|
|
1427
1431
|
closeTorrent(pid);
|
|
1428
1432
|
reject(err);
|
|
1429
1433
|
};
|
|
1430
|
-
const { pid, stdout, stderr } = child_process.spawn((0, types_1.sanitizeCmd)(ARIA2.BIN
|
|
1434
|
+
const { pid, stdout, stderr } = child_process.spawn((0, types_1.sanitizeCmd)(ARIA2.BIN, args), { cwd: pathname, shell: true, signal: signal || this.signal, uid: ARIA2.EXEC_UID, gid: ARIA2.EXEC_GID })
|
|
1431
1435
|
.on('exit', code => {
|
|
1432
1436
|
closeTorrent(pid);
|
|
1433
1437
|
if (this.aborted) {
|
|
@@ -1530,6 +1534,7 @@ class Request extends module_1 {
|
|
|
1530
1534
|
if (!RCLONE.BIN) {
|
|
1531
1535
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Binary not found"));
|
|
1532
1536
|
}
|
|
1537
|
+
uri = uri.toString();
|
|
1533
1538
|
let pathname, headers, binOpts, silent;
|
|
1534
1539
|
if ((0, types_1.isString)(options)) {
|
|
1535
1540
|
pathname = options;
|
|
@@ -1537,21 +1542,15 @@ class Request extends module_1 {
|
|
|
1537
1542
|
}
|
|
1538
1543
|
else {
|
|
1539
1544
|
silent = options.silent;
|
|
1540
|
-
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--interactive', '--dry-run'], ['--partial-suffix', '--verbose']);
|
|
1545
|
+
[pathname, headers, binOpts] = parseBinOpts(this, options, ['--interactive', '--dry-run'], ['--partial-suffix', '--verbose'], options.shellExpansion);
|
|
1541
1546
|
}
|
|
1542
1547
|
const command = options.command || 'copy';
|
|
1543
1548
|
let source;
|
|
1544
1549
|
switch (command) {
|
|
1545
1550
|
case 'copy':
|
|
1546
1551
|
case 'copyto':
|
|
1547
|
-
if (module_1.isURL(source = uri.replace(/^rclone:\?/i, ''))) {
|
|
1548
|
-
return Promise.reject((0, types_1.errorMessage)("rclone", "Unsupported protocol", uri));
|
|
1549
|
-
}
|
|
1550
|
-
break;
|
|
1551
1552
|
case 'copyurl':
|
|
1552
|
-
|
|
1553
|
-
return Promise.reject((0, types_1.errorMessage)("rclone", "Unsupported protocol", uri));
|
|
1554
|
-
}
|
|
1553
|
+
source = uri.replace(REGEXP_RCLONE, '');
|
|
1555
1554
|
break;
|
|
1556
1555
|
default:
|
|
1557
1556
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
|
|
@@ -1724,7 +1723,7 @@ class Request extends module_1 {
|
|
|
1724
1723
|
commitLog(types_1.STATUS_TYPE.ERROR, err);
|
|
1725
1724
|
}
|
|
1726
1725
|
};
|
|
1727
|
-
const { stdout, stderr } = child_process.spawn((0, types_1.sanitizeCmd)(RCLONE.BIN
|
|
1726
|
+
const { stdout, stderr } = child_process.spawn((0, types_1.sanitizeCmd)(RCLONE.BIN, args), { cwd, shell: true, signal: this.signal, uid: RCLONE.EXEC_UID, gid: RCLONE.EXEC_GID })
|
|
1728
1727
|
.on('exit', code => {
|
|
1729
1728
|
if (options.signal || this.aborted) {
|
|
1730
1729
|
reject((0, types_1.createAbortError)());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.12.
|
|
24
|
-
"@e-mc/types": "0.12.
|
|
23
|
+
"@e-mc/module": "0.12.3",
|
|
24
|
+
"@e-mc/types": "0.12.3",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^4.0.2",
|