new clients page

This commit is contained in:
2024-12-22 02:39:15 -08:00
parent bdea663178
commit 5015246a24
7 changed files with 129 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { users, wgClients } from './schema';
import { ipAllocations, users, wgClients } from './schema';
import { eq } from 'drizzle-orm';
import assert from 'node:assert';
import { drizzle } from 'drizzle-orm/libsql';
@@ -7,23 +7,27 @@ import * as schema from '$lib/server/db/schema';
assert(process.env.DATABASE_URL, 'DATABASE_URL is not set');
const db = drizzle(process.env.DATABASE_URL, { schema });
export async function seed() {
async function seed() {
const user = await db.query.users.findFirst({ where: eq(users.username, 'CaZzzer') });
assert(user, 'User not found');
const clients = [
const clients: typeof wgClients.$inferInsert[] = [
{
userId: user.id,
name: 'Client1',
publicKey: 'BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=',
privateKey: 'KKqsHDu30WCSrVsyzMkOKbE3saQ+wlx0sBwGs61UGXk=',
preSharedKey: '0LWopbrISXBNHUxr+WOhCSAg+0hD8j3TLmpyzHkBHCQ=',
ipIndex: 1,
// ipIndex: 1,
// allowedIps: '10.18.11.101/32,fd00::1/112',
}
]
},
];
const returned = await db.insert(wgClients).values(clients).returning({ insertedId: wgClients.id });
await db.insert(wgClients).values(clients);
const ipAllocation: typeof ipAllocations.$inferInsert = {
clientId: returned[0].insertedId,
};
await db.insert(ipAllocations).values(ipAllocation);
}
seed();