@lynx-js/rspeedy 0.14.1 → 0.14.3
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/CHANGELOG.md +38 -2
- package/dist/0~src_config_validate_ts.js +2229 -2449
- package/dist/0~src_plugins_dev_plugin_ts.js +30 -4
- package/dist/1~src_cli_init_ts-src_create-rspeedy_ts.js +3 -0
- package/dist/1~src_config_validate_ts.js +2229 -2449
- package/dist/1~src_plugins_dev_plugin_ts.js +30 -4
- package/dist/index.d.ts +93 -33
- package/dist/src_cli_main_ts.js +1 -1
- package/dist/src_index_ts.js +4 -1
- package/package.json +4 -3
|
@@ -160,7 +160,10 @@ async function findIp(family, isInternal = false) {
|
|
|
160
160
|
import("node:os")
|
|
161
161
|
]);
|
|
162
162
|
let host;
|
|
163
|
-
const networks = Object.
|
|
163
|
+
const networks = Object.entries(os.networkInterfaces()).flatMap(([name, networks])=>(networks ?? []).map((network)=>({
|
|
164
|
+
name,
|
|
165
|
+
network
|
|
166
|
+
}))).filter(({ network })=>{
|
|
164
167
|
if (!network || !network.address) return false;
|
|
165
168
|
if (network.family !== `IP${family}`) return false;
|
|
166
169
|
if (network.internal !== isInternal) return false;
|
|
@@ -168,13 +171,36 @@ async function findIp(family, isInternal = false) {
|
|
|
168
171
|
const range = ipaddr.parse(network.address).range();
|
|
169
172
|
if ('ipv4Mapped' !== range && 'uniqueLocal' !== range) return false;
|
|
170
173
|
}
|
|
171
|
-
return
|
|
172
|
-
});
|
|
174
|
+
return true;
|
|
175
|
+
}).sort((left, right)=>getNetworkPriority(left.name, left.network.address) - getNetworkPriority(right.name, right.network.address));
|
|
173
176
|
if (networks.length > 0) {
|
|
174
|
-
host = networks[0].address;
|
|
177
|
+
host = networks[0].network.address;
|
|
175
178
|
if (host.includes(':')) host = `[${host}]`;
|
|
176
179
|
}
|
|
177
180
|
if (!host) throw new Error("No valid IP found");
|
|
178
181
|
return host;
|
|
179
182
|
}
|
|
183
|
+
function getNetworkPriority(name, address) {
|
|
184
|
+
const normalizedName = name.toLowerCase();
|
|
185
|
+
if (isPreferredInterface(normalizedName) && !isLinkLocalIpv4(address)) return 0;
|
|
186
|
+
if (!isVirtualInterface(normalizedName) && !isLinkLocalIpv4(address)) return 1;
|
|
187
|
+
if (!isVirtualInterface(normalizedName)) return 2;
|
|
188
|
+
return 3;
|
|
189
|
+
}
|
|
190
|
+
function isPreferredInterface(name) {
|
|
191
|
+
return /^(?:en\d+|eth\d+|eno\d+|enp\w+|wl\w+)$/.test(name);
|
|
192
|
+
}
|
|
193
|
+
function isVirtualInterface(name) {
|
|
194
|
+
return [
|
|
195
|
+
'utun',
|
|
196
|
+
'tun',
|
|
197
|
+
'tap',
|
|
198
|
+
'awdl',
|
|
199
|
+
'llw',
|
|
200
|
+
'lo'
|
|
201
|
+
].some((prefix)=>name.startsWith(prefix));
|
|
202
|
+
}
|
|
203
|
+
function isLinkLocalIpv4(address) {
|
|
204
|
+
return address.startsWith('169.254.');
|
|
205
|
+
}
|
|
180
206
|
export { pluginDev };
|