| 1 | import { and, eq } from "drizzle-orm"; |
| 2 | import type { NextRequest |
| 3 | import { getAuth } |
| 4 | import { db } |
| 5 | import { nodeAllocations, nodes |
| 6 | import { signWsToken } |
| 7 | |
| 8 | export async function GET |
| 9 | req: NextRequest |
| 10 | { params }: |
| 11 | ) { |
| 12 | const auth = |
| 13 | const session = |
| 14 | if (!session) |
| 15 | |
| 16 | const { id |
| 17 | |
| 18 | const server = |
| 19 | where: eq(servers |
| 20 | with: { node: true |
| 21 | }); |
| 22 | if (!server) |
| 23 | |
| 24 | const isOwner = |
| 25 | const isAdmin = |
| 26 | |
| 27 | if (!isOwner && |
| 28 | const subuserRecord = |
| 29 | where: and( |
| 30 | eq(subusers.userId |
| 31 | eq(subusers.serverId |
| 32 | ), |
| 33 | }); |
| 34 | if (!subuserRecord) |
| 35 | } |
| 36 | |
| 37 | const permissions = |
| 38 | ? ["*"] |
| 39 | : await getSubuserPermissions( |
| 40 | |
| 41 | const node = |
| 42 | const token = |
| 43 | { user_uuid: session. |
| 44 | node.token, |
| 45 | ); |
| 46 | |
| 47 | const wsScheme = |
| 48 | const socketUrl = |
| 49 | |
| 50 | return Response.json |
| 51 | } |
| 52 | |
| 53 | async function getSubuserPermissions |
| 54 | userId: string, |
| 55 | serverId: string, |
| 56 | ): Promise<string |
| 57 | const record = |
| 58 | where: and( |
| 59 | eq(subusers.userId |
| 60 | eq(subusers.serverId |
| 61 | ), |
| 62 | }); |
| 63 | if (!record) |
| 64 | try { |
| 65 | return JSON.parse |
| 66 | } catch { |
| 67 | return []; |
| 68 | } |
| 69 | } |