mirror of
https://github.com/etiennecollin/unifi-voucher-manager.git
synced 2025-11-01 12:33:30 +00:00
refactor: do not hardcode valid types
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { getRuntimeConfig } from "@/utils/runtimeConfig";
|
import { getRuntimeConfig } from "@/utils/runtimeConfig";
|
||||||
|
|
||||||
type WifiType = "WPA" | "WEP" | "nopass";
|
// Derive the type from the array
|
||||||
|
const validWifiTypes = ["WPA", "WEP", "nopass"] as const;
|
||||||
|
type WifiType = (typeof validWifiTypes)[number];
|
||||||
|
|
||||||
export interface WifiConfig {
|
export interface WifiConfig {
|
||||||
ssid: string;
|
ssid: string;
|
||||||
@@ -50,15 +52,15 @@ export function generateWifiConfig(): WifiConfig {
|
|||||||
type_parsed = "nopass";
|
type_parsed = "nopass";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO: Find how to print a type
|
throw `Invalid WiFi type provided: ${type}. Valid types: ${validWifiTypes.join(
|
||||||
throw `Invalid WiFi type provided: ${type}. Valid types: "WPA" | "WEP" | "nopass"`;
|
" | ",
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password && type_parsed === "nopass") {
|
if (password && type_parsed === "nopass") {
|
||||||
throw "Incoherent WiFi configuration: password provided, but type set to 'nopass'";
|
throw "Incoherent WiFi configuration: password provided, but type set to 'nopass'";
|
||||||
} else if (!password && type_parsed !== "nopass") {
|
} else if (!password && type_parsed !== "nopass") {
|
||||||
// TODO: This is true for WPA, but check for WEP
|
|
||||||
throw "Incoherent WiFi configuration: password not provided, but type implies a password";
|
throw "Incoherent WiFi configuration: password not provided, but type implies a password";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user