Files
wireguard-ui/src/functions/backend/setup/expand-client-rule-destinations.ts
T
2026-09-20 07:27:29 +01:00

32 lines
698 B
TypeScript

import type { BUN_SQLITE_WGUI_CLIENT_RULES } from "@/db/types/db";
type Params = {
rule: BUN_SQLITE_WGUI_CLIENT_RULES;
};
export default function expandClientRuleDestinations({ rule }: Params) {
if (rule.rule_type == "all") {
return [rule];
}
const destinations = (rule.destination || "")
.split(",")
.map((value) => value.trim())
.filter(Boolean);
if (destinations.length <= 1) {
return [
{
...rule,
destination: destinations[0] || "",
},
];
}
return destinations.map((destination) => ({
...rule,
id: undefined,
destination,
}));
}