mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-18 18:23:18 +02:00
Add batch update
This commit is contained in:
@@ -13,13 +13,20 @@
|
|||||||
|
|
||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db, remoteExitNodeResources, remoteExitNodes } from "@server/db";
|
import {
|
||||||
|
db,
|
||||||
|
newts,
|
||||||
|
remoteExitNodeResources,
|
||||||
|
remoteExitNodes,
|
||||||
|
sites
|
||||||
|
} from "@server/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { sendToClientsBatch } from "#private/routers/ws";
|
||||||
|
|
||||||
const paramsSchema = z.strictObject({
|
const paramsSchema = z.strictObject({
|
||||||
orgId: z.string().min(1),
|
orgId: z.string().min(1),
|
||||||
@@ -113,6 +120,25 @@ export async function setRemoteExitNodeResources(
|
|||||||
eq(remoteExitNodeResources.remoteExitNodeId, remoteExitNodeId)
|
eq(remoteExitNodeResources.remoteExitNodeId, remoteExitNodeId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Notify all newts connected to this remote exit node's exit node
|
||||||
|
if (remoteExitNode.exitNodeId) {
|
||||||
|
const connectedNewts = await db
|
||||||
|
.select({ newtId: newts.newtId })
|
||||||
|
.from(newts)
|
||||||
|
.innerJoin(sites, eq(newts.siteId, sites.siteId))
|
||||||
|
.where(eq(sites.exitNodeId, remoteExitNode.exitNodeId));
|
||||||
|
|
||||||
|
await sendToClientsBatch(
|
||||||
|
connectedNewts.map(({ newtId }) => ({
|
||||||
|
clientId: newtId,
|
||||||
|
message: {
|
||||||
|
type: "newt/wg/subnets/update",
|
||||||
|
data: { subnets: destinations }
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return response<SetRemoteExitNodeResourcesResponse>(res, {
|
return response<SetRemoteExitNodeResourcesResponse>(res, {
|
||||||
data: { resources },
|
data: { resources },
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user