@e-mc/request 0.9.16 → 0.9.18

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 CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.16/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.18/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -202,9 +202,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
202
202
 
203
203
  ## References
204
204
 
205
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/http.d.ts
206
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/request.d.ts
207
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/settings.d.ts
205
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/http.d.ts
206
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/request.d.ts
207
+ - https://www.unpkg.com/@e-mc/types@0.9.18/lib/settings.d.ts
208
208
 
209
209
  * https://www.npmjs.com/package/@types/node
210
210
 
@@ -5,8 +5,6 @@ const yaml = require("js-yaml");
5
5
  const types_1 = require("@e-mc/types");
6
6
  const module_1 = require("@e-mc/module");
7
7
  const util_1 = require("@e-mc/request/util");
8
- const kOutStream = Symbol('outStream');
9
- const kOptions = Symbol('options');
10
8
  let LOG_TIMEFORMAT = 'readable';
11
9
  class HttpAdapter {
12
10
  instance;
@@ -53,13 +51,13 @@ class HttpAdapter {
53
51
  resolve;
54
52
  reject;
55
53
  startTime;
56
- [kOutStream] = null;
57
- [kOptions];
54
+ #outStream = null;
55
+ #options;
58
56
  constructor(instance, state, uri, options) {
59
57
  this.instance = instance;
60
58
  this.state = state;
61
59
  this.uri = uri;
62
- this[kOptions] = options;
60
+ this.#options = options;
63
61
  this.startTime = state.log ? process.hrtime.bigint() : BigInt(0);
64
62
  this.setOpts();
65
63
  }
@@ -99,14 +97,14 @@ class HttpAdapter {
99
97
  this.retryResponse(statusCode, headers['retry-after']);
100
98
  }
101
99
  else if (HttpAdapter.isUnsupported(statusCode)) {
102
- this.retryDownload(true, this.formatNgFlags(http2.constants.NGHTTP2_PROTOCOL_ERROR, statusCode));
100
+ this.retryDownload(true, this.#formatNgFlags(http2.constants.NGHTTP2_PROTOCOL_ERROR, statusCode));
103
101
  }
104
102
  else {
105
103
  switch (flags) {
106
104
  case http2.constants.NGHTTP2_PROTOCOL_ERROR:
107
105
  case http2.constants.NGHTTP2_INADEQUATE_SECURITY:
108
106
  case http2.constants.NGHTTP2_HTTP_1_1_REQUIRED:
109
- this.retryDownload(true, this.formatNgFlags(flags, statusCode, headers.location));
107
+ this.retryDownload(true, this.#formatNgFlags(flags, statusCode, headers.location));
110
108
  break;
111
109
  default:
112
110
  this.retryDownload(false, this.formatStatus(statusCode));
@@ -194,7 +192,7 @@ class HttpAdapter {
194
192
  if (uri) {
195
193
  this.uri = uri;
196
194
  }
197
- this.opts = this.instance.opts(this.uri, this[kOptions]);
195
+ this.opts = this.instance.opts(this.uri, this.#options);
198
196
  }
199
197
  setWriteStream() {
200
198
  const pipeTo = this.pipeTo;
@@ -462,7 +460,7 @@ class HttpAdapter {
462
460
  return;
463
461
  }
464
462
  }
465
- this.sendWarning(this.formatRetry((0, util_1.fromStatusCode)(statusCode)));
463
+ this.sendWarning(this.#formatRetry((0, util_1.fromStatusCode)(statusCode)));
466
464
  if ((0, util_1.isRetryable)(statusCode, true)) {
467
465
  setImmediate(this.init.bind(this));
468
466
  }
@@ -476,7 +474,7 @@ class HttpAdapter {
476
474
  return (0, util_1.isRetryable)(value) && ++this.retries <= this.retryLimit;
477
475
  }
478
476
  retryTimeout() {
479
- this.sendWarning(this.formatRetry("HTTP connection timeout"));
477
+ this.sendWarning(this.#formatRetry("HTTP connection timeout"));
480
478
  this.init();
481
479
  }
482
480
  terminate(err) {
@@ -509,10 +507,10 @@ class HttpAdapter {
509
507
  this.outStream = null;
510
508
  }
511
509
  }
512
- formatNgFlags(value, statusCode, location) {
510
+ #formatNgFlags(value, statusCode, location) {
513
511
  return location ? `Using HTTP 1.1 for URL redirect (${location})` : this.formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
514
512
  }
515
- formatRetry(message) {
513
+ #formatRetry(message) {
516
514
  return `${message} (${this.retries} / ${this.retryLimit})`;
517
515
  }
518
516
  set abortController(value) {
@@ -522,13 +520,13 @@ class HttpAdapter {
522
520
  return this.opts.outAbort || null;
523
521
  }
524
522
  set outStream(value) {
525
- this[kOutStream] = value;
523
+ this.#outStream = value;
526
524
  if (value) {
527
525
  this.opts.outStream = value;
528
526
  }
529
527
  }
530
528
  get outStream() {
531
- return this[kOutStream];
529
+ return this.#outStream;
532
530
  }
533
531
  get destroyed() {
534
532
  return this.client.destroyed || this.httpVersion === 2 && this.client.aborted;
package/index.js CHANGED
@@ -396,7 +396,7 @@ class Request extends module_1 {
396
396
  if ((lowest_speed_limit = parseSize(lowest_speed_limit, true)) !== undefined) {
397
397
  ARIA2.LOWEST_SPEED_LIMIT = lowest_speed_limit;
398
398
  }
399
- if (always_resume) {
399
+ if (typeof always_resume === 'boolean') {
400
400
  ARIA2.ALWAYS_RESUME = always_resume;
401
401
  }
402
402
  if ((0, types_1.isString)(file_allocation)) {
@@ -410,7 +410,7 @@ class Request extends module_1 {
410
410
  break;
411
411
  }
412
412
  }
413
- if (conf_path && this.isPath(conf_path = path.resolve(conf_path))) {
413
+ if (conf_path === '' || (0, types_1.isString)(conf_path) && this.isPath(conf_path = path.resolve(conf_path))) {
414
414
  ARIA2.CONF_PATH = conf_path;
415
415
  }
416
416
  }
@@ -1080,7 +1080,7 @@ class Request extends module_1 {
1080
1080
  case 'string': {
1081
1081
  const value = opt.trim();
1082
1082
  if (value.startsWith('--')) {
1083
- const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)$/.exec(value);
1083
+ const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)$/s.exec(value);
1084
1084
  if (match) {
1085
1085
  switch (match[1]) {
1086
1086
  case '--daemon':
@@ -1135,8 +1135,8 @@ class Request extends module_1 {
1135
1135
  ({ protocol, origin, username, password, href: uri } = uri);
1136
1136
  }
1137
1137
  const escapeQuote = (value) => {
1138
- value = value.replace(/"/g, '\\"');
1139
- return PLATFORM_WIN32 ? value : value.replace(/[ $`]/g, capture => (capture !== ' ' ? '\\' : '') + '\\' + capture);
1138
+ value = value.replace(/(?<!\\)"/g, '\\"');
1139
+ return PLATFORM_WIN32 ? value : value.replace(/(?<!\\)\$/g, '\\$');
1140
1140
  };
1141
1141
  const init = [
1142
1142
  `--dir="${escapeQuote(pathname)}"`,
@@ -1281,10 +1281,13 @@ class Request extends module_1 {
1281
1281
  }
1282
1282
  if (binOpts) {
1283
1283
  for (const leading of binOpts) {
1284
- for (let i = 0; i < opts.length; ++i) {
1285
- if (opts[i].startsWith(leading)) {
1286
- opts.splice(i--, i);
1287
- break;
1284
+ if (leading.startsWith('-')) {
1285
+ const pattern = new RegExp(`^${leading}(?:=|$)`);
1286
+ for (let i = 0; i < opts.length; ++i) {
1287
+ if (pattern.test(opts[i])) {
1288
+ opts.splice(i--, i);
1289
+ break;
1290
+ }
1288
1291
  }
1289
1292
  }
1290
1293
  }
@@ -1301,18 +1304,14 @@ class Request extends module_1 {
1301
1304
  opts.push(`"${escapeQuote(uri)}"`);
1302
1305
  args = args.concat(init, opts);
1303
1306
  const startTime = Date.now();
1304
- let out = '', message = '', aborted;
1307
+ let out = '', message = '';
1305
1308
  const errorResponse = (pid, err) => {
1306
- aborted = true;
1307
1309
  closeTorrent(pid);
1308
1310
  reject(err);
1309
1311
  };
1310
1312
  const { pid, stdout, stderr } = child_process.spawn(module_1.sanitizeCmd(ARIA2.BIN), args, { cwd: pathname, shell: true, signal: this.signal, uid: ARIA2.EXEC_UID, gid: ARIA2.EXEC_GID })
1311
1313
  .on('exit', code => {
1312
1314
  closeTorrent(pid);
1313
- if (aborted) {
1314
- return;
1315
- }
1316
1315
  if (this.aborted) {
1317
1316
  errorResponse(pid, (0, types_1.createAbortError)());
1318
1317
  return;
@@ -1344,10 +1343,15 @@ class Request extends module_1 {
1344
1343
  }
1345
1344
  }
1346
1345
  }
1347
- if (result.length && !silent && LOG_HTTP && LOG_TIMEPROCESS) {
1348
- this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
1346
+ if (result.length > 0) {
1347
+ if (!silent && LOG_HTTP && LOG_TIMEPROCESS) {
1348
+ this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
1349
+ }
1350
+ this.addLog(types_1.STATUS_TYPE.INFO, out, currentTime, currentTime - startTime, "aria2", uri);
1351
+ }
1352
+ else {
1353
+ this.addLog(types_1.STATUS_TYPE.ERROR, "No files were successfully downloaded", currentTime, currentTime - startTime, "aria2", uri);
1349
1354
  }
1350
- this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2", uri);
1351
1355
  resolve(result);
1352
1356
  })
1353
1357
  .on('error', err => errorResponse(pid, err));
@@ -1759,7 +1763,7 @@ class Request extends module_1 {
1759
1763
  else {
1760
1764
  options = {};
1761
1765
  }
1762
- const headers = (0, util_1.parseOutgoingHeaders)(options.headers ||= {});
1766
+ const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
1763
1767
  for (const attr in headers) {
1764
1768
  const name = attr.toLowerCase();
1765
1769
  if (name === 'content-type' || name === 'content-length') {
@@ -1875,6 +1879,7 @@ class Request extends module_1 {
1875
1879
  options.httpVersion = 1;
1876
1880
  options.postData = data;
1877
1881
  headers['content-type'] = contentType || "text/plain";
1882
+ options.headers = headers;
1878
1883
  return this.get(uri, options);
1879
1884
  }
1880
1885
  async get(uri, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
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.9.16",
24
- "@e-mc/types": "0.9.16",
23
+ "@e-mc/module": "0.9.18",
24
+ "@e-mc/types": "0.9.18",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^4.0.2",