Update setupWireguardHost function to grab clients from database

This commit is contained in:
2026-09-13 07:55:28 +01:00
parent 0ecac621c5
commit e057d21e75
2 changed files with 59 additions and 2 deletions
@@ -9,6 +9,8 @@ import { execSync } from "node:child_process";
import path from "node:path";
import grabHostNetworkInterface from "./grab-host-network-interface";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import BunSQLite from "@moduletrace/bun-sqlite";
import type { TableType } from "@/src/types";
const {
WGUI_LIB_IP_TABLES_DIR,
@@ -18,18 +20,32 @@ const {
} = grabDirNames();
type Params = {
clients: BUN_SQLITE_WGUI_CLIENTS[];
host?: BUN_SQLITE_WGUI_HOSTS;
variables?: BUN_SQLITE_WGUI_VARIABLES[];
};
export default async function setupWireguardHost({
clients,
host,
variables,
}: Params): Promise<APIResponseObject> {
const host_id = host?.id || AppData["WireguardHostID"];
const host_clients_res = await BunSQLite.select<
BUN_SQLITE_WGUI_CLIENTS,
TableType
>({
table: "clients",
query: {
query: {
host_id: {
value: host_id,
},
},
},
});
const clients = host_clients_res.payload || [];
const TARGET_INTERFACE = await grabHostNetworkInterface();
const HOST_WG_IP =
host?.wg_ip_address ||