mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-05 10:16:41 +00:00
Newt registration?
This commit is contained in:
@@ -19,7 +19,7 @@ const createSiteSchema = z.object({
|
||||
name: z.string().min(1).max(255),
|
||||
exitNodeId: z.number().int().positive(),
|
||||
subdomain: z.string().min(1).max(255).optional(),
|
||||
pubKey: z.string(),
|
||||
pubKey: z.string().optional(),
|
||||
subnet: z.string(),
|
||||
});
|
||||
|
||||
@@ -68,16 +68,24 @@ export async function createSite(
|
||||
|
||||
const niceId = await getUniqueSiteName(orgId);
|
||||
|
||||
let payload: any = {
|
||||
orgId,
|
||||
exitNodeId,
|
||||
name,
|
||||
niceId,
|
||||
subnet,
|
||||
};
|
||||
|
||||
if (pubKey) {
|
||||
payload = {
|
||||
...payload,
|
||||
pubKey,
|
||||
};
|
||||
}
|
||||
|
||||
const [newSite] = await db
|
||||
.insert(sites)
|
||||
.values({
|
||||
orgId,
|
||||
exitNodeId,
|
||||
name,
|
||||
niceId,
|
||||
pubKey,
|
||||
subnet,
|
||||
})
|
||||
.values(payload)
|
||||
.returning();
|
||||
|
||||
const adminRole = await db
|
||||
@@ -105,11 +113,13 @@ export async function createSite(
|
||||
});
|
||||
}
|
||||
|
||||
// add the peer to the exit node
|
||||
await addPeer(exitNodeId, {
|
||||
publicKey: pubKey,
|
||||
allowedIps: [],
|
||||
});
|
||||
if (pubKey) {
|
||||
// add the peer to the exit node
|
||||
await addPeer(exitNodeId, {
|
||||
publicKey: pubKey,
|
||||
allowedIps: [],
|
||||
});
|
||||
}
|
||||
|
||||
return response(res, {
|
||||
data: {
|
||||
|
||||
@@ -48,7 +48,9 @@ export async function deleteSite(
|
||||
);
|
||||
}
|
||||
|
||||
await deletePeer(deletedSite.exitNodeId!, deletedSite.pubKey);
|
||||
if (deletedSite.pubKey) {
|
||||
await deletePeer(deletedSite.exitNodeId!, deletedSite.pubKey);
|
||||
}
|
||||
|
||||
return response(res, {
|
||||
data: null,
|
||||
@@ -79,7 +81,7 @@ async function removePeer(publicKey: string) {
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("Peer removed successfully:", data.status);
|
||||
logger.info("Peer removed successfully:", data.status);
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
console.error("Error removing peer:", error.message);
|
||||
|
||||
Reference in New Issue
Block a user