mirror of
https://github.com/koush/scrypted.git
synced 2026-05-05 22:00:27 +01:00
fix: add type annotations for network address functions
- Add parseInt with empty string fallback for undefined env vars - getIpAddress returns string | undefined when no addresses available - Add type guard filters for network interface arrays
This commit is contained in:
@@ -70,6 +70,7 @@ export function getUsableNetworkAddresses() {
|
||||
const getUsable = (family: string | number) => {
|
||||
const usable = Object.values(nis)
|
||||
.flat()
|
||||
.filter((details): details is os.NetworkInterfaceInfo => !!details)
|
||||
.filter((details) => details.family === family)
|
||||
.filter(details => isUsableNetworkAddress(details.address));
|
||||
return usable;
|
||||
@@ -84,7 +85,7 @@ export function getUsableNetworkAddresses() {
|
||||
const fixedAddresses = ipv6.filter(details => details.address.includes('::'));
|
||||
const fixedRanges = fixedAddresses.map(details => {
|
||||
const block = new net.BlockList();
|
||||
const cidr = parseInt(details.address.split('/')[1]) || 1;
|
||||
const cidr = parseInt(details.address.split('/')[1] ?? '') || 1;
|
||||
block.addSubnet(details.address, cidr, 'ipv6');
|
||||
return block;
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { getUsableNetworkAddresses } from './ip';
|
||||
|
||||
export const SCRYPTED_INSECURE_PORT = parseInt(process.env.SCRYPTED_INSECURE_PORT) || 11080;
|
||||
export const SCRYPTED_SECURE_PORT = parseInt(process.env.SCRYPTED_SECURE_PORT) || 10443;
|
||||
export const SCRYPTED_DEBUG_PORT = parseInt(process.env.SCRYPTED_DEBUG_PORT) || 10081;
|
||||
export const SCRYPTED_CLUSTER_WORKERS = parseInt(process.env.SCRYPTED_CLUSTER_WORKERS) || 32;
|
||||
export const SCRYPTED_INSECURE_PORT = parseInt(process.env.SCRYPTED_INSECURE_PORT ?? '') || 11080;
|
||||
export const SCRYPTED_SECURE_PORT = parseInt(process.env.SCRYPTED_SECURE_PORT ?? '') || 10443;
|
||||
export const SCRYPTED_DEBUG_PORT = parseInt(process.env.SCRYPTED_DEBUG_PORT ?? '') || 10081;
|
||||
export const SCRYPTED_CLUSTER_WORKERS = parseInt(process.env.SCRYPTED_CLUSTER_WORKERS ?? '') || 32;
|
||||
|
||||
export function getIpAddress(): string {
|
||||
export function getIpAddress(): string | undefined {
|
||||
return getUsableNetworkAddresses()[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user