mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-05 12:10:52 +02:00
add targets and refactor endpoints
This commit is contained in:
@@ -14,7 +14,6 @@ export async function verifyApiKeyAiProviderAccess(
|
||||
const apiKey = req.apiKey;
|
||||
const providerIdRaw = getFirstString(req.params.providerId);
|
||||
const providerId = Number.parseInt(providerIdRaw ?? "", 10);
|
||||
const orgId = getFirstString(req.params.orgId);
|
||||
|
||||
if (!apiKey) {
|
||||
return next(
|
||||
@@ -22,52 +21,16 @@ export async function verifyApiKeyAiProviderAccess(
|
||||
);
|
||||
}
|
||||
|
||||
if (!orgId) {
|
||||
return next(
|
||||
createHttpError(HttpCode.BAD_REQUEST, "Invalid organization ID")
|
||||
);
|
||||
}
|
||||
|
||||
if (Number.isNaN(providerId)) {
|
||||
return next(
|
||||
createHttpError(HttpCode.BAD_REQUEST, "Invalid provider ID")
|
||||
);
|
||||
}
|
||||
|
||||
if (apiKey.isRoot) {
|
||||
const [provider] = await db
|
||||
.select()
|
||||
.from(aiProviders)
|
||||
.where(
|
||||
and(
|
||||
eq(aiProviders.providerId, providerId),
|
||||
eq(aiProviders.orgId, orgId)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (!provider) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.NOT_FOUND,
|
||||
`AI provider with ID ${providerId} not found`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
req.aiProvider = provider;
|
||||
return next();
|
||||
}
|
||||
|
||||
const [provider] = await db
|
||||
.select()
|
||||
.from(aiProviders)
|
||||
.where(
|
||||
and(
|
||||
eq(aiProviders.providerId, providerId),
|
||||
eq(aiProviders.orgId, orgId)
|
||||
)
|
||||
)
|
||||
.where(eq(aiProviders.providerId, providerId))
|
||||
.limit(1);
|
||||
|
||||
if (!provider) {
|
||||
@@ -79,7 +42,14 @@ export async function verifyApiKeyAiProviderAccess(
|
||||
);
|
||||
}
|
||||
|
||||
if (!req.apiKeyOrg) {
|
||||
if (apiKey.isRoot) {
|
||||
req.aiProvider = provider;
|
||||
return next();
|
||||
}
|
||||
|
||||
const orgId = provider.orgId;
|
||||
|
||||
if (!req.apiKeyOrg || req.apiKeyOrg.orgId !== orgId) {
|
||||
const apiKeyOrgRes = await db
|
||||
.select()
|
||||
.from(apiKeyOrg)
|
||||
|
||||
Reference in New Issue
Block a user