@abtnode/util 1.16.23-beta-06c3a221 → 1.16.23-beta-a2f9b088
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/lib/url-evaluation/index.js +12 -2
- package/package.json +10 -10
|
@@ -20,16 +20,24 @@ const isCustomDomain = (domain) => {
|
|
|
20
20
|
return !isIpEcho(domain) && !isDidDomain(domain) && !isSlpDomain(domain) && !isIpAddress(domain);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {Object} EvaluateURLOptions
|
|
25
|
+
* @property {boolean} [preferAccessible=false] - 是否优先考虑可访问性
|
|
26
|
+
* @property {number} [timeout=5000] - 超时时间
|
|
27
|
+
*/
|
|
28
|
+
|
|
23
29
|
/**
|
|
24
30
|
* 用于评估 url 可访问性/使用优先级 (考虑 node/browser 两种环境)
|
|
31
|
+
* @param {string} url
|
|
32
|
+
* @param {EvaluateURLOptions} options
|
|
25
33
|
*/
|
|
26
|
-
const evaluateURL = async (url, options = {}) => {
|
|
34
|
+
const evaluateURL = async (url, options = { preferAccessible: false }) => {
|
|
27
35
|
const { timeout = 5000, checkAccessible = checkURLAccessibleInBrowser } = options;
|
|
28
36
|
const { protocol, port, hostname } = new URL(url);
|
|
29
37
|
// https +1000 分
|
|
30
38
|
let score = protocol === 'https:' ? 1000 : 0;
|
|
31
39
|
// 自定义域名,优先级最高 (即使不可访问)
|
|
32
|
-
if (isCustomDomain(hostname)) {
|
|
40
|
+
if (isCustomDomain(hostname) && !options.preferAccessible) {
|
|
33
41
|
score += 30000;
|
|
34
42
|
// 子层越多越靠后
|
|
35
43
|
score -= hostname.split('.').length;
|
|
@@ -70,6 +78,8 @@ const evaluateURL = async (url, options = {}) => {
|
|
|
70
78
|
|
|
71
79
|
/**
|
|
72
80
|
* 用于评估一组 url 的可访问性/使用优先级, 返回一组按 score 从高到低排序的 urls
|
|
81
|
+
* @param {string[]} urls
|
|
82
|
+
* @param {EvaluateURLOptions} options
|
|
73
83
|
*/
|
|
74
84
|
const evaluateURLs = async (urls, options = {}) => {
|
|
75
85
|
const results = await Promise.all(
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.23-beta-
|
|
6
|
+
"version": "1.16.23-beta-a2f9b088",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.23-beta-
|
|
22
|
-
"@abtnode/logger": "1.16.23-beta-
|
|
23
|
-
"@blocklet/constant": "1.16.23-beta-
|
|
24
|
-
"@blocklet/meta": "1.16.23-beta-
|
|
25
|
-
"@ocap/client": "1.18.
|
|
26
|
-
"@ocap/mcrypto": "1.18.
|
|
27
|
-
"@ocap/util": "1.18.
|
|
28
|
-
"@ocap/wallet": "1.18.
|
|
21
|
+
"@abtnode/constant": "1.16.23-beta-a2f9b088",
|
|
22
|
+
"@abtnode/logger": "1.16.23-beta-a2f9b088",
|
|
23
|
+
"@blocklet/constant": "1.16.23-beta-a2f9b088",
|
|
24
|
+
"@blocklet/meta": "1.16.23-beta-a2f9b088",
|
|
25
|
+
"@ocap/client": "1.18.110",
|
|
26
|
+
"@ocap/mcrypto": "1.18.110",
|
|
27
|
+
"@ocap/util": "1.18.110",
|
|
28
|
+
"@ocap/wallet": "1.18.110",
|
|
29
29
|
"archiver": "^5.3.1",
|
|
30
30
|
"axios": "^0.27.2",
|
|
31
31
|
"axios-mock-adapter": "^1.21.2",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"fs-extra": "^11.2.0",
|
|
77
77
|
"jest": "^29.7.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "cc060de5d06e1759112a787dd10b780e628ce0b7"
|
|
80
80
|
}
|