@e-mc/request 0.12.2 → 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.
Files changed (3) hide show
  1. package/README.md +4 -2
  2. package/index.js +12 -9
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -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
  }
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] + '=' + (0, types_1.sanitizeArgs)(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)) {
@@ -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,17 +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
- source = uri.replace(/^rclone:\?/i, '');
1548
- break;
1549
1552
  case 'copyurl':
1550
- source = uri;
1553
+ source = uri.replace(REGEXP_RCLONE, '');
1551
1554
  break;
1552
1555
  default:
1553
1556
  return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.12.2",
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.2",
24
- "@e-mc/types": "0.12.2",
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",