@abtnode/util 1.16.30-beta-b7f31b10 → 1.16.30-beta-b80c7bcd

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.
Files changed (2) hide show
  1. package/lib/get-ip.js +20 -6
  2. package/package.json +7 -6
package/lib/get-ip.js CHANGED
@@ -1,3 +1,4 @@
1
+ const isIp = require('is-ip');
1
2
  const internalIp = require('internal-ip');
2
3
  const externalIp = require('public-ip');
3
4
  const debug = require('debug')('core:util:get-ip');
@@ -16,6 +17,13 @@ const getExternalIp = async ({ v6 = false, timeout = 5000 } = {}) => {
16
17
  }
17
18
  };
18
19
 
20
+ const ensureFormat = ({ internal, external, internalV6, externalV6 }) => ({
21
+ internal: internal && isIp.v4(internal) ? internal : '',
22
+ external: external && isIp.v4(external) ? external : '',
23
+ internalV6: internalV6 && isIp.v6(internalV6) ? internalV6 : '',
24
+ externalV6: externalV6 && isIp.v6(externalV6) ? externalV6 : '',
25
+ });
26
+
19
27
  /**
20
28
  * @description
21
29
  * @param {{
@@ -36,12 +44,12 @@ const getIP = async ({ includeV6 = false, timeout = 5000, includeExternal = true
36
44
  debug('check env', { inEc2, inGCP });
37
45
 
38
46
  if (process.env.ABT_NODE_HOST) {
39
- return {
47
+ return ensureFormat({
40
48
  internal: process.env.ABT_NODE_HOST,
41
49
  external: process.env.ABT_NODE_HOST,
42
50
  internalV6: process.env.ABT_NODE_HOST,
43
51
  externalV6: process.env.ABT_NODE_HOST,
44
- };
52
+ });
45
53
  }
46
54
 
47
55
  if (inEc2) {
@@ -54,7 +62,7 @@ const getIP = async ({ includeV6 = false, timeout = 5000, includeExternal = true
54
62
  ]);
55
63
 
56
64
  debug('got ips in ec2', { internal, external, internalV6, externalV6 });
57
- return { internal, external, internalV6, externalV6 };
65
+ return ensureFormat({ internal, external, internalV6, externalV6 });
58
66
  }
59
67
 
60
68
  if (inGCP) {
@@ -67,7 +75,7 @@ const getIP = async ({ includeV6 = false, timeout = 5000, includeExternal = true
67
75
  ]);
68
76
 
69
77
  debug('got ips in gcp', { internal, external, internalV6, externalV6 });
70
- return { internal, external, internalV6, externalV6 };
78
+ return ensureFormat({ internal, external, internalV6, externalV6 });
71
79
  }
72
80
 
73
81
  const [internal, external, internalV6, externalV6] = await Promise.all([
@@ -76,9 +84,15 @@ const getIP = async ({ includeV6 = false, timeout = 5000, includeExternal = true
76
84
  includeV6 ? internalIp.v6() : '',
77
85
  includeV6 && includeExternal ? getExternalIp({ v6: true, timeout }) : '',
78
86
  ]);
79
- return { internal, external, internalV6, externalV6 };
87
+
88
+ return ensureFormat({ internal, external, internalV6, externalV6 });
80
89
  } catch (err) {
81
- return {};
90
+ return {
91
+ internal: '',
92
+ external: '',
93
+ internalV6: '',
94
+ externalV6: '',
95
+ };
82
96
  }
83
97
  };
84
98
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.30-beta-b7f31b10",
6
+ "version": "1.16.30-beta-b80c7bcd",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,11 +18,11 @@
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.30-beta-b7f31b10",
22
- "@abtnode/logger": "1.16.30-beta-b7f31b10",
21
+ "@abtnode/constant": "1.16.30-beta-b80c7bcd",
22
+ "@abtnode/logger": "1.16.30-beta-b80c7bcd",
23
23
  "@arcblock/pm2": "^5.4.0",
24
- "@blocklet/constant": "1.16.30-beta-b7f31b10",
25
- "@blocklet/meta": "1.16.30-beta-b7f31b10",
24
+ "@blocklet/constant": "1.16.30-beta-b80c7bcd",
25
+ "@blocklet/meta": "1.16.30-beta-b80c7bcd",
26
26
  "@ocap/client": "1.18.128",
27
27
  "@ocap/mcrypto": "1.18.128",
28
28
  "@ocap/util": "1.18.128",
@@ -47,6 +47,7 @@
47
47
  "hpagent": "^1.1.0",
48
48
  "internal-ip": "^6.2.0",
49
49
  "is-docker": "^2.2.1",
50
+ "is-ip": "3",
50
51
  "is-url": "^1.2.4",
51
52
  "json-stable-stringify": "^1.0.1",
52
53
  "lodash": "^4.17.21",
@@ -80,5 +81,5 @@
80
81
  "fs-extra": "^11.2.0",
81
82
  "jest": "^29.7.0"
82
83
  },
83
- "gitHead": "2d429b619b7b54b5603fb05761d3acd9ff674c2c"
84
+ "gitHead": "9d68833290b1a59357b7c362018416b82b5d1503"
84
85
  }