mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-01 08:34:53 +02:00
Converting more multi site
This commit is contained in:
parent
926ec831e2
commit
dac49f7fdc
2 changed files with 16 additions and 5 deletions
|
@ -18,9 +18,7 @@ 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 { eq, and } from "drizzle-orm";
|
import { eq, and } from "drizzle-orm";
|
||||||
import { addPeer } from "../newt/peers";
|
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { newts } from "@server/db/schema";
|
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { hashPassword } from "@server/auth/password";
|
import { hashPassword } from "@server/auth/password";
|
||||||
|
|
||||||
|
@ -122,7 +120,6 @@ export async function createClient(
|
||||||
const [newClient] = await trx
|
const [newClient] = await trx
|
||||||
.insert(clients)
|
.insert(clients)
|
||||||
.values({
|
.values({
|
||||||
siteId,
|
|
||||||
orgId: site.orgId,
|
orgId: site.orgId,
|
||||||
name,
|
name,
|
||||||
subnet,
|
subnet,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import { clients, olms, sites } from "@server/db/schema";
|
import { clients, exitNodes, olms, sites } from "@server/db/schema";
|
||||||
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";
|
||||||
|
@ -19,6 +19,7 @@ const getSiteSchema = z
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export type PickClientDefaultsResponse = {
|
export type PickClientDefaultsResponse = {
|
||||||
|
exitNodeId: number;
|
||||||
siteId: number;
|
siteId: number;
|
||||||
address: string;
|
address: string;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
|
@ -66,8 +67,20 @@ export async function pickClientDefaults(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure all the required fields are present
|
// TODO: more intelligent way to pick the exit node
|
||||||
|
|
||||||
|
// make sure there is an exit node by counting the exit nodes table
|
||||||
|
const nodes = await db.select().from(exitNodes);
|
||||||
|
if (nodes.length === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.NOT_FOUND, "No exit nodes available")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the first exit node
|
||||||
|
const exitNode = nodes[0];
|
||||||
|
|
||||||
|
// make sure all the required fields are present
|
||||||
const sitesRequiredFields = z.object({
|
const sitesRequiredFields = z.object({
|
||||||
address: z.string(),
|
address: z.string(),
|
||||||
publicKey: z.string(),
|
publicKey: z.string(),
|
||||||
|
@ -95,6 +108,7 @@ export async function pickClientDefaults(
|
||||||
|
|
||||||
return response<PickClientDefaultsResponse>(res, {
|
return response<PickClientDefaultsResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
|
exitNodeId: exitNode.exitNodeId,
|
||||||
siteId: site.siteId,
|
siteId: site.siteId,
|
||||||
address: address,
|
address: address,
|
||||||
publicKey: publicKey,
|
publicKey: publicKey,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue