Error & Format fixing
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import type { NetworkValidation } from "@app/validation/config/network.js";
|
import type { NetworkValidation } from "@app/validation/config/network.js";
|
||||||
import { DynamicForm } from "@components/Form/DynamicForm.js";
|
import { DynamicForm } from "@components/Form/DynamicForm.js";
|
||||||
import { useDevice } from "@core/stores/deviceStore.js";
|
import { useDevice } from "@core/stores/deviceStore.js";
|
||||||
|
import {
|
||||||
|
convertIntToIpAddress,
|
||||||
|
convertIpAddressToInt,
|
||||||
|
} from "@core/utils/ip.js";
|
||||||
import { Protobuf } from "@meshtastic/js";
|
import { Protobuf } from "@meshtastic/js";
|
||||||
import { convertIntToIpAddress, convertIpAddressToInt } from "@core/utils/ip.js";
|
|
||||||
|
|
||||||
export const Network = (): JSX.Element => {
|
export const Network = (): JSX.Element => {
|
||||||
const { config, setWorkingConfig } = useDevice();
|
const { config, setWorkingConfig } = useDevice();
|
||||||
@@ -21,7 +24,7 @@ export const Network = (): JSX.Element => {
|
|||||||
},
|
},
|
||||||
ntpServer: config.network?.ntpServer,
|
ntpServer: config.network?.ntpServer,
|
||||||
rsyslogServer: config.network?.rsyslogServer,
|
rsyslogServer: config.network?.rsyslogServer,
|
||||||
}
|
};
|
||||||
|
|
||||||
const onSubmit = (data: NetworkValidation) => {
|
const onSubmit = (data: NetworkValidation) => {
|
||||||
setWorkingConfig(
|
setWorkingConfig(
|
||||||
@@ -30,14 +33,12 @@ export const Network = (): JSX.Element => {
|
|||||||
case: "network",
|
case: "network",
|
||||||
value: {
|
value: {
|
||||||
...data,
|
...data,
|
||||||
ipv4Config: new Protobuf.Config.Config_NetworkConfig_IpV4Config(
|
ipv4Config: new Protobuf.Config.Config_NetworkConfig_IpV4Config({
|
||||||
{
|
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
|
||||||
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
|
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
|
||||||
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
|
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
|
||||||
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
|
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
|
||||||
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
|
}),
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ export function convertIntToIpAddress(int: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function convertIpAddressToInt(ip: string): number | null {
|
export function convertIpAddressToInt(ip: string): number | null {
|
||||||
const parts = ip.split('.').map(Number).reverse(); // little-endian byte order
|
const parts = ip.split(".").map(Number).reverse(); // little-endian byte order
|
||||||
|
|
||||||
if (parts.some(Number.isNaN)) {
|
if (parts.some(Number.isNaN)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts.reduce((total, part) => (total << 8) | part, 0);
|
return parts.reduce((total, part) => (total << 8) | part, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,10 @@ export class NetworkValidation
|
|||||||
|
|
||||||
export class NetworkValidationIpV4Config
|
export class NetworkValidationIpV4Config
|
||||||
implements
|
implements
|
||||||
Omit<Protobuf.Config.Config_NetworkConfig_IpV4Config, keyof Message>
|
Omit<
|
||||||
|
Protobuf.Config.Config_NetworkConfig_IpV4Config,
|
||||||
|
keyof Message | "ip" | "gateway" | "subnet" | "dns"
|
||||||
|
>
|
||||||
{
|
{
|
||||||
@IsIP()
|
@IsIP()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
Reference in New Issue
Block a user