mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-14 13:46:36 +03:00
optimizations
This commit is contained in:
@@ -3,6 +3,23 @@ import type { NetworkSettingsType } from 'types';
|
||||
|
||||
import { HOSTNAME_VALIDATOR, IP_ADDRESS_VALIDATOR } from './shared';
|
||||
|
||||
// Reusable validator rules
|
||||
const REQUIRED_IP_VALIDATOR = (fieldName: string) => [
|
||||
{ required: true, message: `${fieldName} is required` },
|
||||
IP_ADDRESS_VALIDATOR
|
||||
];
|
||||
|
||||
const OPTIONAL_IP_VALIDATOR = [IP_ADDRESS_VALIDATOR];
|
||||
|
||||
// Helper to create static IP validation rules
|
||||
const createStaticIpRules = () => ({
|
||||
local_ip: REQUIRED_IP_VALIDATOR('Local IP'),
|
||||
gateway_ip: REQUIRED_IP_VALIDATOR('Gateway IP'),
|
||||
subnet_mask: REQUIRED_IP_VALIDATOR('Subnet mask'),
|
||||
dns_ip_1: OPTIONAL_IP_VALIDATOR,
|
||||
dns_ip_2: OPTIONAL_IP_VALIDATOR
|
||||
});
|
||||
|
||||
export const createNetworkSettingsValidator = (
|
||||
networkSettings: NetworkSettingsType
|
||||
) =>
|
||||
@@ -17,29 +34,16 @@ export const createNetworkSettingsValidator = (
|
||||
message: 'BSSID must be 17 characters or empty'
|
||||
}
|
||||
],
|
||||
password: {
|
||||
type: 'string',
|
||||
max: 64,
|
||||
message: 'Password must be 64 characters or less'
|
||||
},
|
||||
password: [
|
||||
{
|
||||
type: 'string',
|
||||
max: 64,
|
||||
message: 'Password must be 64 characters or less'
|
||||
}
|
||||
],
|
||||
hostname: [
|
||||
{ required: true, message: 'Hostname is required' },
|
||||
HOSTNAME_VALIDATOR
|
||||
],
|
||||
...(networkSettings.static_ip_config && {
|
||||
local_ip: [
|
||||
{ required: true, message: 'Local IP is required' },
|
||||
IP_ADDRESS_VALIDATOR
|
||||
],
|
||||
gateway_ip: [
|
||||
{ required: true, message: 'Gateway IP is required' },
|
||||
IP_ADDRESS_VALIDATOR
|
||||
],
|
||||
subnet_mask: [
|
||||
{ required: true, message: 'Subnet mask is required' },
|
||||
IP_ADDRESS_VALIDATOR
|
||||
],
|
||||
dns_ip_1: IP_ADDRESS_VALIDATOR,
|
||||
dns_ip_2: IP_ADDRESS_VALIDATOR
|
||||
})
|
||||
...(networkSettings.static_ip_config && createStaticIpRules())
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user