32 lines
698 B
TypeScript
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,
|
|
}));
|
|
}
|