mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-03 17:44:44 +02:00
Newt registration?
This commit is contained in:
parent
e141263b7e
commit
40734184af
11 changed files with 89 additions and 53 deletions
42
server/routers/newt/handleRegisterMessage.ts
Normal file
42
server/routers/newt/handleRegisterMessage.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import db from "@server/db";
|
||||
import { MessageHandler } from "../ws";
|
||||
import { sites } from "@server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const handleRegisterMessage: MessageHandler = async (context) => {
|
||||
const { message, newt, sendToClient } = context;
|
||||
|
||||
if (!newt) {
|
||||
console.log("Newt not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newt.siteId) {
|
||||
console.log("Newt has no site!"); // TODO: Maybe we create the site here?
|
||||
return;
|
||||
}
|
||||
|
||||
const siteId = newt.siteId;
|
||||
|
||||
// get the site
|
||||
const site = await db
|
||||
.select()
|
||||
.from(sites)
|
||||
.where(eq(sites.siteId, siteId))
|
||||
.limit(1);
|
||||
|
||||
|
||||
const { publicKey } = message.data;
|
||||
|
||||
return {
|
||||
message: {
|
||||
type: 'newt/wg/connect',
|
||||
data: {
|
||||
publicKey: 'publicKey',
|
||||
|
||||
}
|
||||
},
|
||||
broadcast: false, // Send to all clients
|
||||
excludeSender: false // Include sender in broadcast
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue