kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
1faf1b707a
commit
1ec6e5e04b
|
@ -6,6 +6,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { acl } from '@/lib/acl'
|
||||
import { publishDeployment } from '@/lib/deployments/publish-deployment'
|
||||
import { resolveDeploymentVersion } from '@/lib/deployments/resolve-deployment-version'
|
||||
import { validateDeploymentOriginAdapter } from '@/lib/deployments/validate-deployment-origin-adapter'
|
||||
import { ensureAuthUser } from '@/lib/ensure-auth-user'
|
||||
import {
|
||||
openapiAuthenticatedSecuritySchemas,
|
||||
|
@ -13,7 +14,7 @@ import {
|
|||
openapiErrorResponse409,
|
||||
openapiErrorResponses
|
||||
} from '@/lib/openapi-utils'
|
||||
import { assert, parseZodSchema, sha256 } from '@/lib/utils'
|
||||
import { assert, parseZodSchema, pick, sha256 } from '@/lib/utils'
|
||||
|
||||
import { createDeploymentQuerySchema } from './schemas'
|
||||
|
||||
|
@ -62,8 +63,6 @@ export function registerV1DeploymentsCreateDeployment(
|
|||
|
||||
// validatePricingPlans(ctx, pricingPlans)
|
||||
|
||||
// TODO: validate OpenAPI origin schema
|
||||
|
||||
const project = await db.query.projects.findFirst({
|
||||
where: eq(schema.projects.id, projectId),
|
||||
with: {
|
||||
|
@ -99,6 +98,12 @@ export function registerV1DeploymentsCreateDeployment(
|
|||
})
|
||||
}
|
||||
|
||||
// Validate OpenAPI originUrl and originAdapter
|
||||
await validateDeploymentOriginAdapter({
|
||||
...pick(body, 'originUrl', 'originAdapter'),
|
||||
deploymentId
|
||||
})
|
||||
|
||||
let [[deployment]] = await db.transaction(async (tx) => {
|
||||
return Promise.all([
|
||||
// Create the deployment
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import type { DeploymentOriginAdapter } from '@/db/schema'
|
||||
import { assert } from '@/lib/utils'
|
||||
|
||||
export async function validateDeploymentOriginAdapter({
|
||||
deploymentId,
|
||||
originUrl,
|
||||
originAdapter
|
||||
}: {
|
||||
deploymentId: string
|
||||
originUrl: string
|
||||
originAdapter: DeploymentOriginAdapter
|
||||
}): Promise<void> {
|
||||
assert(
|
||||
originUrl,
|
||||
400,
|
||||
`Origin URL is required for deployment "${deploymentId}"`
|
||||
)
|
||||
|
||||
if (originAdapter.type === 'openapi') {
|
||||
// TODO: Validate OpenAPI spec
|
||||
assert(
|
||||
originAdapter.spec,
|
||||
400,
|
||||
`OpenAPI spec is required for deployment "${deploymentId}"`
|
||||
)
|
||||
|
||||
// TODO: Validate OpenAPI spec version is the same as `originAdapter.version`
|
||||
|
||||
// TODO: Remove origin servers from the OpenAPI spec and if they exist, ensure
|
||||
// that `originUrl` matches.
|
||||
} else {
|
||||
assert(
|
||||
originAdapter.type === 'raw',
|
||||
400,
|
||||
`Invalid origin adapter type "${originAdapter.type}" for deployment "${deploymentId}"`
|
||||
)
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue