@e-mc/request 0.11.2 → 0.11.4
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 +4 -4
- package/index.js +28 -19
- 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.11.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.11.4/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -209,9 +209,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
209
209
|
|
|
210
210
|
## References
|
|
211
211
|
|
|
212
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
213
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
214
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
212
|
+
- https://www.unpkg.com/@e-mc/types@0.11.4/lib/http.d.ts
|
|
213
|
+
- https://www.unpkg.com/@e-mc/types@0.11.4/lib/request.d.ts
|
|
214
|
+
- https://www.unpkg.com/@e-mc/types@0.11.4/lib/settings.d.ts
|
|
215
215
|
|
|
216
216
|
* https://www.npmjs.com/package/@types/node
|
|
217
217
|
|
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ const kStatusOn = Symbol('statusOn');
|
|
|
37
37
|
const kHeadersOn = Symbol('headersOn');
|
|
38
38
|
const kAdapter = Symbol('adapter');
|
|
39
39
|
const SUPPORTED_NODE20 = (0, types_1.supported)(20);
|
|
40
|
+
const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) && typeof zlib.createZstdDecompress === 'function';
|
|
40
41
|
const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
|
|
41
42
|
const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
|
|
42
43
|
const HTTP = {
|
|
@@ -328,6 +329,9 @@ function decompressEncoding(value, chunkSize) {
|
|
|
328
329
|
if (LIB_ZSTD) {
|
|
329
330
|
return new LIB_ZSTD.ZstdDecompressTransform({ writableHighWaterMark: chunkSize });
|
|
330
331
|
}
|
|
332
|
+
if (SUPPORTED_ZSTD) {
|
|
333
|
+
return zlib.createZstdDecompress({ chunkSize });
|
|
334
|
+
}
|
|
331
335
|
break;
|
|
332
336
|
}
|
|
333
337
|
}
|
|
@@ -345,8 +349,8 @@ function resetAria2() {
|
|
|
345
349
|
ARIA2.PID_TIMER = null;
|
|
346
350
|
}
|
|
347
351
|
function escapeShellQuote(value) {
|
|
348
|
-
value = value.
|
|
349
|
-
return module_1.PLATFORM_WIN32 ? value : value.replace(/
|
|
352
|
+
value = value.replace(/(?<!\\)"/g, '\\"');
|
|
353
|
+
return module_1.PLATFORM_WIN32 ? value : value.replace(/(?<!\\)\$/g, '\\$');
|
|
350
354
|
}
|
|
351
355
|
function failedDns(err, pending) {
|
|
352
356
|
for (const cb of pending) {
|
|
@@ -448,7 +452,7 @@ class Request extends module_1 {
|
|
|
448
452
|
if ((lowest_speed_limit = parseSize(lowest_speed_limit, true)) !== undefined) {
|
|
449
453
|
ARIA2.LOWEST_SPEED_LIMIT = lowest_speed_limit;
|
|
450
454
|
}
|
|
451
|
-
if (always_resume) {
|
|
455
|
+
if (typeof always_resume === 'boolean') {
|
|
452
456
|
ARIA2.ALWAYS_RESUME = always_resume;
|
|
453
457
|
}
|
|
454
458
|
if ((0, types_1.isString)(file_allocation)) {
|
|
@@ -462,7 +466,7 @@ class Request extends module_1 {
|
|
|
462
466
|
break;
|
|
463
467
|
}
|
|
464
468
|
}
|
|
465
|
-
if (conf_path && this.isPath(conf_path = path.resolve(conf_path))) {
|
|
469
|
+
if (conf_path === '' || (0, types_1.isString)(conf_path) && this.isPath(conf_path = path.resolve(conf_path))) {
|
|
466
470
|
ARIA2.CONF_PATH = conf_path;
|
|
467
471
|
}
|
|
468
472
|
}
|
|
@@ -986,7 +990,7 @@ class Request extends module_1 {
|
|
|
986
990
|
case 'string': {
|
|
987
991
|
const value = opt.trim();
|
|
988
992
|
if (value.startsWith('--')) {
|
|
989
|
-
const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)
|
|
993
|
+
const match = /^(--[a-z]+[a-z0-9-]*)(=)?\s*(.*)$/s.exec(value);
|
|
990
994
|
if (match) {
|
|
991
995
|
switch (match[1]) {
|
|
992
996
|
case '--daemon':
|
|
@@ -1188,10 +1192,13 @@ class Request extends module_1 {
|
|
|
1188
1192
|
}
|
|
1189
1193
|
if (binOpts) {
|
|
1190
1194
|
for (const leading of binOpts) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
+
if (leading.startsWith('-')) {
|
|
1196
|
+
const pattern = new RegExp(`^${leading}(?:=|$)`);
|
|
1197
|
+
for (let i = 0; i < opts.length; ++i) {
|
|
1198
|
+
if (pattern.test(opts[i])) {
|
|
1199
|
+
opts.splice(i--, i);
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1195
1202
|
}
|
|
1196
1203
|
}
|
|
1197
1204
|
}
|
|
@@ -1208,18 +1215,14 @@ class Request extends module_1 {
|
|
|
1208
1215
|
opts.push(`"${escapeShellQuote(uri)}"`);
|
|
1209
1216
|
args = args.concat(init, opts);
|
|
1210
1217
|
const startTime = Date.now();
|
|
1211
|
-
let out = '', message = ''
|
|
1218
|
+
let out = '', message = '';
|
|
1212
1219
|
const errorResponse = (pid, err) => {
|
|
1213
|
-
aborted = true;
|
|
1214
1220
|
closeTorrent(pid);
|
|
1215
1221
|
reject(err);
|
|
1216
1222
|
};
|
|
1217
1223
|
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 })
|
|
1218
1224
|
.on('exit', code => {
|
|
1219
1225
|
closeTorrent(pid);
|
|
1220
|
-
if (aborted) {
|
|
1221
|
-
return;
|
|
1222
|
-
}
|
|
1223
1226
|
if (this.aborted) {
|
|
1224
1227
|
errorResponse(pid, (0, types_1.createAbortError)());
|
|
1225
1228
|
return;
|
|
@@ -1255,10 +1258,15 @@ class Request extends module_1 {
|
|
|
1255
1258
|
}
|
|
1256
1259
|
}
|
|
1257
1260
|
}
|
|
1258
|
-
if (result.length > 0
|
|
1259
|
-
|
|
1261
|
+
if (result.length > 0) {
|
|
1262
|
+
if (!silent && LOG_HTTP && LOG_TIMEPROCESS) {
|
|
1263
|
+
this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
|
|
1264
|
+
}
|
|
1265
|
+
this.addLog(types_1.STATUS_TYPE.INFO, out, currentTime, currentTime - startTime, "aria2", uri);
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
this.addLog(types_1.STATUS_TYPE.ERROR, "No files were successfully downloaded", currentTime, currentTime - startTime, "aria2", uri);
|
|
1260
1269
|
}
|
|
1261
|
-
this.addLog(result.length > 0 ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2", uri);
|
|
1262
1270
|
resolve(result);
|
|
1263
1271
|
})
|
|
1264
1272
|
.on('error', err => {
|
|
@@ -1429,7 +1437,7 @@ class Request extends module_1 {
|
|
|
1429
1437
|
const baseHeaders = this.headersOf(uri);
|
|
1430
1438
|
let request, ca, cert, key, ciphers, minVersion;
|
|
1431
1439
|
if (getting && this.acceptEncoding && !host.localhost && !baseHeaders?.['accept-encoding']) {
|
|
1432
|
-
(headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : '');
|
|
1440
|
+
(headers ||= {})['accept-encoding'] ||= 'gzip, deflate, br' + (LIB_ZSTD || SUPPORTED_ZSTD ? ', zstd' : '');
|
|
1433
1441
|
}
|
|
1434
1442
|
if (posting && options.postData) {
|
|
1435
1443
|
if (expectContinue) {
|
|
@@ -1763,7 +1771,7 @@ class Request extends module_1 {
|
|
|
1763
1771
|
else {
|
|
1764
1772
|
options = {};
|
|
1765
1773
|
}
|
|
1766
|
-
const headers = (0, util_1.parseOutgoingHeaders)(options.headers
|
|
1774
|
+
const headers = (0, util_1.parseOutgoingHeaders)(options.headers) || {};
|
|
1767
1775
|
for (const attr in headers) {
|
|
1768
1776
|
const name = attr.toLowerCase();
|
|
1769
1777
|
if (name === 'content-type' || name === 'content-length') {
|
|
@@ -1873,6 +1881,7 @@ class Request extends module_1 {
|
|
|
1873
1881
|
options.httpVersion = 1;
|
|
1874
1882
|
options.postData = data;
|
|
1875
1883
|
headers['content-type'] = contentType || "text/plain";
|
|
1884
|
+
options.headers = headers;
|
|
1876
1885
|
return this.get(uri, options);
|
|
1877
1886
|
}
|
|
1878
1887
|
async get(uri, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
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.11.
|
|
24
|
-
"@e-mc/types": "0.11.
|
|
23
|
+
"@e-mc/module": "0.11.4",
|
|
24
|
+
"@e-mc/types": "0.11.4",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"picomatch": "^4.0.2",
|