@abtnode/util 1.7.6 → 1.7.9
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.
|
@@ -62,7 +62,7 @@ module.exports = async ({
|
|
|
62
62
|
host = '127.0.0.1',
|
|
63
63
|
port,
|
|
64
64
|
timeout = 10 * ONE_SECOND,
|
|
65
|
-
minConsecutiveTime = 5 * ONE_SECOND,
|
|
65
|
+
minConsecutiveTime = (+process.env.ENDPOINT_CONSECUTIVE_TIME || 5) * ONE_SECOND,
|
|
66
66
|
}) => {
|
|
67
67
|
debug('ensure endpoint healthy', { port, minConsecutiveTime });
|
|
68
68
|
|
|
@@ -1,30 +1,47 @@
|
|
|
1
1
|
const checkURLAccessibleInBrowser = require('./check-accessible-browser');
|
|
2
2
|
|
|
3
|
+
const isIpAddress = (hostname) => {
|
|
4
|
+
return /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(hostname);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const isIpEcho = (hostname) => {
|
|
8
|
+
return hostname.endsWith('.ip.abtnet.io');
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const isDidDomain = (hostname) => {
|
|
12
|
+
return hostname.endsWith('.did.abtnet.io');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const isCustomDomain = (domain) => {
|
|
16
|
+
return !isIpEcho(domain) && !isDidDomain(domain) && !isIpAddress(domain);
|
|
17
|
+
};
|
|
18
|
+
|
|
3
19
|
/**
|
|
4
20
|
* 用于评估 url 可访问性/使用优先级 (考虑 node/browser 两种环境)
|
|
5
21
|
*/
|
|
6
22
|
const evaluateURL = async (url, options = {}) => {
|
|
7
23
|
const { timeout = 5000, checkAccessible = checkURLAccessibleInBrowser } = options;
|
|
8
24
|
const { protocol, port, hostname } = new URL(url);
|
|
9
|
-
//
|
|
25
|
+
// https +1000 分
|
|
10
26
|
let score = protocol === 'https:' ? 1000 : 0;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
score +=
|
|
27
|
+
// 自定义域名,优先级最高 (即使不可访问)
|
|
28
|
+
if (isCustomDomain(hostname)) {
|
|
29
|
+
score += 30000;
|
|
30
|
+
// 子层越多越靠后
|
|
31
|
+
score -= hostname.split('.').length;
|
|
14
32
|
} else {
|
|
33
|
+
// ip echo, +20
|
|
34
|
+
if (isIpEcho(hostname)) {
|
|
35
|
+
score += 20;
|
|
36
|
+
}
|
|
37
|
+
// 纯 ip 地址
|
|
38
|
+
if (isIpAddress(hostname)) {
|
|
39
|
+
score += 1;
|
|
40
|
+
}
|
|
15
41
|
// 带端口优先权放后
|
|
16
42
|
if (port) {
|
|
17
43
|
score -= 1;
|
|
18
44
|
}
|
|
19
|
-
if (/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(hostname)) {
|
|
20
|
-
// 纯ip地址
|
|
21
|
-
score += 1;
|
|
22
|
-
} else {
|
|
23
|
-
// 自定义域名
|
|
24
|
-
score += 200;
|
|
25
|
-
// 子层越多越靠后
|
|
26
|
-
score -= hostname.split('.').length;
|
|
27
|
-
}
|
|
28
45
|
}
|
|
29
46
|
// 不可访问, 减 20000 分 (这里将 4xx~5xx 也认为是可访问)
|
|
30
47
|
let accessible = false;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.7.
|
|
6
|
+
"version": "1.7.9",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ocap/mcrypto": "^1.16.
|
|
22
|
-
"@ocap/util": "^1.16.
|
|
23
|
-
"@ocap/wallet": "^1.16.
|
|
24
|
-
"axios": "^0.
|
|
21
|
+
"@ocap/mcrypto": "^1.16.4",
|
|
22
|
+
"@ocap/util": "^1.16.4",
|
|
23
|
+
"@ocap/wallet": "^1.16.4",
|
|
24
|
+
"axios": "^0.26.1",
|
|
25
25
|
"axios-mock-adapter": "^1.20.0",
|
|
26
26
|
"axon": "^2.0.3",
|
|
27
27
|
"cross-spawn": "^7.0.3",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"fs-extra": "^10.0.1",
|
|
55
55
|
"jest": "^27.4.5"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "285f4fedd41fcb8e1814ce5d8250ac10616e67e0"
|
|
58
58
|
}
|