@e-mc/request 0.12.15 → 0.12.16
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 +5 -4
- package/http/adapter/index.js +7 -1
- package/index.js +23 -15
- package/package.json +4 -4
- package/util.d.ts +1 -1
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.16/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -45,6 +45,7 @@ interface IRequest extends IModule {
|
|
|
45
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
|
+
blob(uri: string | URL, options?: OpenOptions): Promise<Blob | null>;
|
|
48
49
|
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
49
50
|
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
50
51
|
open(uri: string | URL, options: OpenOptions): HttpRequestClient;
|
|
@@ -255,9 +256,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
255
256
|
|
|
256
257
|
## References
|
|
257
258
|
|
|
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.
|
|
259
|
+
- https://www.unpkg.com/@e-mc/types@0.12.16/lib/http.d.ts
|
|
260
|
+
- https://www.unpkg.com/@e-mc/types@0.12.16/lib/request.d.ts
|
|
261
|
+
- https://www.unpkg.com/@e-mc/types@0.12.16/lib/settings.d.ts
|
|
261
262
|
|
|
262
263
|
* https://www.npmjs.com/package/@types/node
|
|
263
264
|
|
package/http/adapter/index.js
CHANGED
|
@@ -243,6 +243,9 @@ class HttpAdapter {
|
|
|
243
243
|
if ('outFilename' in opts) {
|
|
244
244
|
opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
|
|
245
245
|
}
|
|
246
|
+
if ('outContentType' in opts) {
|
|
247
|
+
opts.outContentType = headers['content-type'];
|
|
248
|
+
}
|
|
246
249
|
const pipeline = this.pipeTo ? !(0, types_1.isString)(this.pipeTo) : false;
|
|
247
250
|
const enabled = opts.connected?.call(this.client, headers) !== false && !pipeline;
|
|
248
251
|
const maxBufferSize = opts.maxBufferSize ? (0, types_1.alignSize)(opts.maxBufferSize) : 0;
|
|
@@ -350,7 +353,7 @@ class HttpAdapter {
|
|
|
350
353
|
break;
|
|
351
354
|
case 'toml':
|
|
352
355
|
try {
|
|
353
|
-
result = require('smol-toml').parse(buffer);
|
|
356
|
+
result = require('smol-toml').parse(buffer, parser);
|
|
354
357
|
}
|
|
355
358
|
catch {
|
|
356
359
|
result = require(packageName = 'toml').parse(buffer);
|
|
@@ -372,6 +375,9 @@ class HttpAdapter {
|
|
|
372
375
|
}
|
|
373
376
|
}
|
|
374
377
|
}
|
|
378
|
+
else if (opts.outFormat) {
|
|
379
|
+
opts.outFormat = undefined;
|
|
380
|
+
}
|
|
375
381
|
if (result === undefined) {
|
|
376
382
|
result = buffer;
|
|
377
383
|
}
|
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const adapter_1 = require("@e-mc/request/http/adapter");
|
|
|
23
23
|
const kRequest = Symbol.for('request:constructor');
|
|
24
24
|
const SUPPORTED_NODE20 = (0, types_1.supported)(20);
|
|
25
25
|
const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) || (0, types_1.supported)(22, 15, 0, true);
|
|
26
|
+
const SUPPORTED_FILE = (0, types_1.supported)(19, 2) || (0, types_1.supported)(18, 13, true);
|
|
26
27
|
const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
|
|
27
28
|
const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
|
|
28
29
|
const REGEXP_RCLONE = /^rclone:\?/i;
|
|
@@ -1218,15 +1219,10 @@ class Request extends module_1 {
|
|
|
1218
1219
|
({ signal, silent } = options);
|
|
1219
1220
|
({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file'], options.shellExpansion));
|
|
1220
1221
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
uri = new URL(uri);
|
|
1224
|
-
}
|
|
1225
|
-
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1226
|
-
}
|
|
1227
|
-
catch (err) {
|
|
1228
|
-
return Promise.reject(err);
|
|
1222
|
+
if ((0, types_1.isString)(uri) && module_1.isURL(uri)) {
|
|
1223
|
+
uri = new URL(uri);
|
|
1229
1224
|
}
|
|
1225
|
+
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1230
1226
|
silent ??= this.#singleton;
|
|
1231
1227
|
return new Promise((resolve, reject) => {
|
|
1232
1228
|
let protocol, origin, username, password;
|
|
@@ -1491,12 +1487,7 @@ class Request extends module_1 {
|
|
|
1491
1487
|
default:
|
|
1492
1488
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
|
|
1493
1489
|
}
|
|
1494
|
-
|
|
1495
|
-
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1496
|
-
}
|
|
1497
|
-
catch (err) {
|
|
1498
|
-
return Promise.reject(err);
|
|
1499
|
-
}
|
|
1490
|
+
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1500
1491
|
silent ??= this.#singleton;
|
|
1501
1492
|
return new Promise((resolve, reject) => {
|
|
1502
1493
|
const init = [
|
|
@@ -1690,6 +1681,21 @@ class Request extends module_1 {
|
|
|
1690
1681
|
options.format = 'json';
|
|
1691
1682
|
return this.get(uri, options);
|
|
1692
1683
|
}
|
|
1684
|
+
async blob(uri, options = {}) {
|
|
1685
|
+
options.outContentType = undefined;
|
|
1686
|
+
options.outFilename = undefined;
|
|
1687
|
+
options.outBlob = true;
|
|
1688
|
+
const data = await this.get(uri, options);
|
|
1689
|
+
if (!data) {
|
|
1690
|
+
return null;
|
|
1691
|
+
}
|
|
1692
|
+
const format = options.outFormat?.out;
|
|
1693
|
+
const type = { type: format ? 'application/' + format : options.outContentType || (typeof data === 'string' ? 'text/plain' : undefined) };
|
|
1694
|
+
if (SUPPORTED_FILE && options.outFilename) {
|
|
1695
|
+
return new File([Buffer.from(data)], path.basename(options.outFilename), type);
|
|
1696
|
+
}
|
|
1697
|
+
return new Blob([Buffer.from(data)], type);
|
|
1698
|
+
}
|
|
1693
1699
|
async pipe(uri, to, options = {}) {
|
|
1694
1700
|
options.pipeTo = to;
|
|
1695
1701
|
return this.get(uri, options);
|
|
@@ -1757,7 +1763,9 @@ class Request extends module_1 {
|
|
|
1757
1763
|
}
|
|
1758
1764
|
headers.accept += ', text/plain';
|
|
1759
1765
|
options.encoding = (0, types_1.getEncoding)(encoding);
|
|
1760
|
-
options.
|
|
1766
|
+
if (!options.outBlob) {
|
|
1767
|
+
options.outFormat = { out: format, parser };
|
|
1768
|
+
}
|
|
1761
1769
|
}
|
|
1762
1770
|
if (typeof uri !== 'string') {
|
|
1763
1771
|
url = uri;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.16",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,11 +19,11 @@
|
|
|
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.16",
|
|
23
|
+
"@e-mc/types": "0.12.16",
|
|
24
24
|
"combined-stream": "^1.0.8",
|
|
25
25
|
"js-yaml": "^4.1.1",
|
|
26
|
-
"picomatch": "^4.0.
|
|
26
|
+
"picomatch": "^4.0.4",
|
|
27
27
|
"which": "^4.0.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/util.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare namespace util {
|
|
|
13
13
|
function hasBasicAuth(value: string): boolean;
|
|
14
14
|
function checkRetryable(err: unknown): boolean;
|
|
15
15
|
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
16
|
-
function parseHttpProxy(value?: string): HttpProxySettings | undefined;
|
|
16
|
+
function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
|
|
17
17
|
function trimPath(value: string, char?: string): string;
|
|
18
18
|
function asInt(value: unknown): number;
|
|
19
19
|
function asFloat(value: unknown): number;
|