mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-15 08:49:59 +02:00
add niceId to provider
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { join } from "path";
|
||||
import { readFileSync } from "fs";
|
||||
import {
|
||||
aiProviders,
|
||||
clients,
|
||||
db,
|
||||
resourcePolicies,
|
||||
@@ -113,6 +114,32 @@ export async function getUniqueResourceName(orgId: string): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUniqueProviderName(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 aiProviderCount = await db
|
||||
.select({
|
||||
niceId: aiProviders.niceId,
|
||||
orgId: aiProviders.orgId
|
||||
})
|
||||
.from(aiProviders)
|
||||
.where(
|
||||
and(eq(aiProviders.niceId, name), eq(aiProviders.orgId, orgId))
|
||||
);
|
||||
|
||||
if (aiProviderCount.length === 0) {
|
||||
return name;
|
||||
}
|
||||
loops++;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUniqueResourcePolicyName(
|
||||
orgId: string
|
||||
): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user