@e-mc/request 0.6.0 → 0.7.1
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/http/host/index.d.ts +4 -4
- package/index.d.ts +4 -4
- package/index.js +60 -55
- package/package.json +3 -3
package/http/host/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HttpHostConstructor } from '../../../types/lib/request';
|
|
2
|
-
|
|
3
|
-
declare const HttpHost: HttpHostConstructor;
|
|
4
|
-
|
|
1
|
+
import type { HttpHostConstructor } from '../../../types/lib/request';
|
|
2
|
+
|
|
3
|
+
declare const HttpHost: HttpHostConstructor;
|
|
4
|
+
|
|
5
5
|
export = HttpHost;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RequestConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Request: RequestConstructor;
|
|
4
|
-
|
|
1
|
+
import type { RequestConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Request: RequestConstructor;
|
|
4
|
+
|
|
5
5
|
export = Request;
|
package/index.js
CHANGED
|
@@ -77,6 +77,7 @@ let READ_TIMEOUT = 0;
|
|
|
77
77
|
let AGENT_TIMEOUT = 0;
|
|
78
78
|
let LOG_HTTP = false;
|
|
79
79
|
let LOG_TIMEPROCESS = true;
|
|
80
|
+
let LOG_STDOUT = true;
|
|
80
81
|
let LOG_TIMEFORMAT = 'readable';
|
|
81
82
|
let LIB_ZSTD = null;
|
|
82
83
|
try {
|
|
@@ -395,9 +396,10 @@ class Request extends module_1.default {
|
|
|
395
396
|
LOG_TIMEFORMAT = time_format;
|
|
396
397
|
break;
|
|
397
398
|
}
|
|
398
|
-
LOG_HTTP = this.hasLogType(1024 /* LOG_TYPE.HTTP */);
|
|
399
|
-
LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
|
|
400
399
|
}
|
|
400
|
+
LOG_HTTP = this.hasLogType(1024 /* LOG_TYPE.HTTP */);
|
|
401
|
+
LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
|
|
402
|
+
LOG_STDOUT = module_1.default.hasLogType(32768 /* LOG_TYPE.STDOUT */);
|
|
401
403
|
return true;
|
|
402
404
|
}
|
|
403
405
|
return false;
|
|
@@ -685,62 +687,60 @@ class Request extends module_1.default {
|
|
|
685
687
|
this.module = data;
|
|
686
688
|
}
|
|
687
689
|
flushLog() {
|
|
690
|
+
const log = this._logQueued;
|
|
688
691
|
if (this[kSingleton]) {
|
|
689
|
-
|
|
690
|
-
if (LOG_HTTP) {
|
|
691
|
-
this[kConnectHttp] = [{}, {}];
|
|
692
|
-
}
|
|
693
|
-
return;
|
|
692
|
+
log.length = 0;
|
|
694
693
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
694
|
+
else {
|
|
695
|
+
if (log.length && !this.host?.aborted) {
|
|
696
|
+
const output = [];
|
|
697
|
+
let count = 0;
|
|
698
|
+
this[kConnectHttp].forEach((protocol, index) => {
|
|
699
|
+
const title = 'HTTP' + (index + 1);
|
|
700
|
+
for (const origin in protocol) {
|
|
701
|
+
const value = protocol[origin];
|
|
702
|
+
const args = [];
|
|
703
|
+
for (let i = 0; i < log.length; ++i) {
|
|
704
|
+
const item = log[i];
|
|
705
|
+
if (Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
|
|
706
|
+
item[1] = '';
|
|
707
|
+
item[2][0] = item[2][0].substring(origin.length);
|
|
708
|
+
item[4].titleBgColor = undefined;
|
|
709
|
+
item[4].titleJustify = 'right';
|
|
710
|
+
args.push(item);
|
|
711
|
+
log.splice(i--, 1);
|
|
712
|
+
}
|
|
713
713
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
count = Math.max(count, value);
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
if (!this.host?.aborted) {
|
|
720
|
-
output.sort((a, b) => b[2] - a[2]);
|
|
721
|
-
const width = count.toString().length;
|
|
722
|
-
output.forEach(item => {
|
|
723
|
-
const [title, origin, downloads, messages] = item;
|
|
724
|
-
const options = { ...title === 'HTTP1' ? module_1.default.LOG_STYLE_NOTICE : module_1.default.LOG_STYLE_INFO };
|
|
725
|
-
if (messages.length === 1) {
|
|
726
|
-
const message = messages[0];
|
|
727
|
-
message[1] = title;
|
|
728
|
-
message[2] = [origin + message[2][0], message[2][1]];
|
|
729
|
-
message[4] = Object.assign(message[4], options);
|
|
730
|
-
module_1.default.formatMessage(...message);
|
|
731
|
-
}
|
|
732
|
-
else {
|
|
733
|
-
this.formatMessage(1024 /* LOG_TYPE.HTTP */, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
|
|
734
|
-
messages.forEach(args => {
|
|
735
|
-
args[4].titleIndent = true;
|
|
736
|
-
module_1.default.formatMessage(...args);
|
|
737
|
-
});
|
|
714
|
+
output.push([title, origin, value, args]);
|
|
715
|
+
count = Math.max(count, value);
|
|
738
716
|
}
|
|
739
717
|
});
|
|
718
|
+
if (LOG_STDOUT) {
|
|
719
|
+
output.sort((a, b) => b[2] - a[2]);
|
|
720
|
+
const width = count.toString().length;
|
|
721
|
+
output.forEach(item => {
|
|
722
|
+
const [title, origin, downloads, messages] = item;
|
|
723
|
+
const options = { ...title === 'HTTP1' ? module_1.default.LOG_STYLE_NOTICE : module_1.default.LOG_STYLE_INFO };
|
|
724
|
+
if (messages.length === 1) {
|
|
725
|
+
const message = messages[0];
|
|
726
|
+
message[1] = title;
|
|
727
|
+
message[2] = [origin + message[2][0], message[2][1]];
|
|
728
|
+
message[4] = Object.assign(message[4], options);
|
|
729
|
+
module_1.default.formatMessage(...message);
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
this.formatMessage(1024 /* LOG_TYPE.HTTP */, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
|
|
733
|
+
messages.forEach(args => {
|
|
734
|
+
args[4].titleIndent = true;
|
|
735
|
+
module_1.default.formatMessage(...args);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
740
|
}
|
|
741
|
-
|
|
741
|
+
super.flushLog();
|
|
742
742
|
}
|
|
743
|
-
|
|
743
|
+
this[kConnectHttp] = [{}, {}];
|
|
744
744
|
}
|
|
745
745
|
detach(singleton) {
|
|
746
746
|
if (typeof singleton === 'boolean') {
|
|
@@ -1172,8 +1172,13 @@ class Request extends module_1.default {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
args = binOpts.concat(args);
|
|
1174
1174
|
}
|
|
1175
|
-
if (args.length
|
|
1176
|
-
|
|
1175
|
+
if (args.length) {
|
|
1176
|
+
if (module_1.default.hasLogType(32768 /* LOG_TYPE.STDOUT */)) {
|
|
1177
|
+
this.formatMessage(32768 /* LOG_TYPE.STDOUT */, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
|
|
1178
|
+
}
|
|
1179
|
+
else {
|
|
1180
|
+
this.addLog(types_1.STATUS_TYPE.INFO, path.basename(ARIA2.BIN) + ' ' + args.join(' '), "aria2" /* VALUES.ARIA2 */);
|
|
1181
|
+
}
|
|
1177
1182
|
}
|
|
1178
1183
|
opts.push(`"${escapeQuote(uri)}"`);
|
|
1179
1184
|
args = args.concat(init, opts);
|
|
@@ -1221,7 +1226,7 @@ class Request extends module_1.default {
|
|
|
1221
1226
|
}
|
|
1222
1227
|
}
|
|
1223
1228
|
if (result.length && !silent && LOG_HTTP && LOG_TIMEPROCESS) {
|
|
1224
|
-
this.writeTimeProcess("aria2" /* VALUES.ARIA2 */, uri, startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: true, messageUnit, messageUnitMinWidth: 9 });
|
|
1229
|
+
this.writeTimeProcess("aria2" /* VALUES.ARIA2 */, uri, startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: true, messageUnit, messageUnitMinWidth: 9, bypassLog: true });
|
|
1225
1230
|
}
|
|
1226
1231
|
this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2" /* VALUES.ARIA2 */, uri);
|
|
1227
1232
|
resolve(result);
|
|
@@ -1975,7 +1980,7 @@ class Request extends module_1.default {
|
|
|
1975
1980
|
}
|
|
1976
1981
|
resolve(result);
|
|
1977
1982
|
if (log) {
|
|
1978
|
-
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog:
|
|
1983
|
+
this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: LOG_STDOUT });
|
|
1979
1984
|
}
|
|
1980
1985
|
});
|
|
1981
1986
|
host.success(httpVersion);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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.
|
|
24
|
-
"@e-mc/types": "0.
|
|
23
|
+
"@e-mc/module": "0.7.1",
|
|
24
|
+
"@e-mc/types": "0.7.1",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"which": "^2.0.2"
|