Resource identified with niceId now

This commit is contained in:
Owen
2025-09-08 17:50:07 -07:00
parent a947a74194
commit fe6e3b013e
9 changed files with 44 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
import { join } from "path";
import { readFileSync } from "fs";
import { db } from "@server/db";
import { db, resources } from "@server/db";
import { exitNodes, sites } from "@server/db";
import { eq, and } from "drizzle-orm";
import { __DIRNAME } from "@server/lib/consts";
@@ -34,6 +34,25 @@ export async function getUniqueSiteName(orgId: string): Promise<string> {
}
}
export async function getUniqueResourceName(orgId: string): Promise<string> {
let loops = 0;
while (true) {
if (loops > 100) {
throw new Error("Could not generate a unique name");
}
const name = generateName();
const count = await db
.select({ niceId: resources.niceId, orgId: resources.orgId })
.from(resources)
.where(and(eq(resources.niceId, name), eq(resources.orgId, orgId)));
if (count.length === 0) {
return name;
}
loops++;
}
}
export async function getUniqueExitNodeEndpointName(): Promise<string> {
let loops = 0;
const count = await db