kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
0c5df27270
commit
0defbb5d69
|
@ -2,7 +2,14 @@ import { assert } from '@agentic/platform-core'
|
||||||
import { parseFaasIdentifier } from '@agentic/platform-validators'
|
import { parseFaasIdentifier } from '@agentic/platform-validators'
|
||||||
|
|
||||||
import type { AuthenticatedContext } from '@/lib/types'
|
import type { AuthenticatedContext } from '@/lib/types'
|
||||||
import { db, deploymentIdSchema, eq, type RawDeployment, schema } from '@/db'
|
import {
|
||||||
|
and,
|
||||||
|
db,
|
||||||
|
deploymentIdSchema,
|
||||||
|
eq,
|
||||||
|
type RawDeployment,
|
||||||
|
schema
|
||||||
|
} from '@/db'
|
||||||
import { ensureAuthUser } from '@/lib/ensure-auth-user'
|
import { ensureAuthUser } from '@/lib/ensure-auth-user'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,52 +70,65 @@ export async function tryGetDeploymentByIdentifier(
|
||||||
assert(deployment, 404, `Deployment not found "${deploymentIdentifier}"`)
|
assert(deployment, 404, `Deployment not found "${deploymentIdentifier}"`)
|
||||||
|
|
||||||
return deployment
|
return deployment
|
||||||
} else if (version === 'latest') {
|
} else if (version) {
|
||||||
const project = await db.query.projects.findFirst({
|
const project = await db.query.projects.findFirst({
|
||||||
...dbQueryOpts,
|
...dbQueryOpts,
|
||||||
where: eq(schema.projects.identifier, projectIdentifier)
|
where: eq(schema.projects.identifier, projectIdentifier)
|
||||||
})
|
})
|
||||||
assert(project, 404, `Project not found "${projectIdentifier}"`)
|
assert(project, 404, `Project not found "${projectIdentifier}"`)
|
||||||
assert(
|
|
||||||
project.lastPublishedDeploymentId,
|
|
||||||
404,
|
|
||||||
'Project has no published deployments'
|
|
||||||
)
|
|
||||||
|
|
||||||
const deployment = await db.query.deployments.findFirst({
|
if (version === 'latest') {
|
||||||
...dbQueryOpts,
|
assert(
|
||||||
where: eq(schema.deployments.id, project.lastPublishedDeploymentId)
|
project.lastPublishedDeploymentId,
|
||||||
})
|
404,
|
||||||
assert(
|
'Project has no published deployments'
|
||||||
deployment,
|
)
|
||||||
404,
|
|
||||||
`Deployment not found "${project.lastPublishedDeploymentId}"`
|
|
||||||
)
|
|
||||||
|
|
||||||
return deployment
|
const deployment = await db.query.deployments.findFirst({
|
||||||
} else if (version === 'dev') {
|
...dbQueryOpts,
|
||||||
const project = await db.query.projects.findFirst({
|
where: eq(schema.deployments.id, project.lastPublishedDeploymentId)
|
||||||
...dbQueryOpts,
|
})
|
||||||
where: eq(schema.projects.id, projectIdentifier)
|
assert(
|
||||||
})
|
deployment,
|
||||||
assert(project, 404, `Project not found "${projectIdentifier}"`)
|
404,
|
||||||
assert(
|
`Deployment not found "${project.lastPublishedDeploymentId}"`
|
||||||
project.lastDeploymentId,
|
)
|
||||||
404,
|
|
||||||
'Project has no published deployments'
|
|
||||||
)
|
|
||||||
|
|
||||||
const deployment = await db.query.deployments.findFirst({
|
return deployment
|
||||||
...dbQueryOpts,
|
} else if (version === 'dev') {
|
||||||
where: eq(schema.deployments.id, project.lastDeploymentId)
|
assert(
|
||||||
})
|
project.lastDeploymentId,
|
||||||
assert(
|
404,
|
||||||
deployment,
|
'Project has no published deployments'
|
||||||
404,
|
)
|
||||||
`Deployment not found "${project.lastDeploymentId}"`
|
|
||||||
)
|
|
||||||
|
|
||||||
return deployment
|
const deployment = await db.query.deployments.findFirst({
|
||||||
|
...dbQueryOpts,
|
||||||
|
where: eq(schema.deployments.id, project.lastDeploymentId)
|
||||||
|
})
|
||||||
|
assert(
|
||||||
|
deployment,
|
||||||
|
404,
|
||||||
|
`Deployment not found "${project.lastDeploymentId}"`
|
||||||
|
)
|
||||||
|
|
||||||
|
return deployment
|
||||||
|
} else {
|
||||||
|
const deployment = await db.query.deployments.findFirst({
|
||||||
|
...dbQueryOpts,
|
||||||
|
where: and(
|
||||||
|
eq(schema.deployments.projectId, project.id),
|
||||||
|
eq(schema.deployments.version, version)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
assert(
|
||||||
|
deployment,
|
||||||
|
404,
|
||||||
|
`Deployment not found "${projectIdentifier}@${version}"`
|
||||||
|
)
|
||||||
|
|
||||||
|
return deployment
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false, 400, `Invalid Deployment identifier "${deploymentIdentifier}"`)
|
assert(false, 400, `Invalid Deployment identifier "${deploymentIdentifier}"`)
|
||||||
|
|
|
@ -19,12 +19,12 @@ const projectToolRe =
|
||||||
/^([a-zA-Z0-9-]{1,64}\/[a-z0-9-]{2,64})(\/[a-zA-Z0-9\-._~%!$&'()*+,;=:/]*)?$/
|
/^([a-zA-Z0-9-]{1,64}\/[a-z0-9-]{2,64})(\/[a-zA-Z0-9\-._~%!$&'()*+,;=:/]*)?$/
|
||||||
|
|
||||||
export function parseFaasUri(uri: string): ParsedFaasIdentifier | undefined {
|
export function parseFaasUri(uri: string): ParsedFaasIdentifier | undefined {
|
||||||
const pdsMatch = uri.match(projectDeploymentToolRe)
|
const pdtMatch = uri.match(projectDeploymentToolRe)
|
||||||
|
|
||||||
if (pdsMatch) {
|
if (pdtMatch) {
|
||||||
const projectIdentifier = pdsMatch[1]!
|
const projectIdentifier = pdtMatch[1]!
|
||||||
const deploymentHash = pdsMatch[2]!
|
const deploymentHash = pdtMatch[2]!
|
||||||
const toolPath = pdsMatch[3] || '/'
|
const toolPath = pdtMatch[3] || '/'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
projectIdentifier,
|
projectIdentifier,
|
||||||
|
@ -34,22 +34,22 @@ export function parseFaasUri(uri: string): ParsedFaasIdentifier | undefined {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pvsMatch = uri.match(projectVersionToolRe)
|
const pvtMatch = uri.match(projectVersionToolRe)
|
||||||
|
|
||||||
if (pvsMatch) {
|
if (pvtMatch) {
|
||||||
return {
|
return {
|
||||||
projectIdentifier: pvsMatch[1]!,
|
projectIdentifier: pvtMatch[1]!,
|
||||||
version: pvsMatch[2]!,
|
version: pvtMatch[2]!,
|
||||||
toolPath: pvsMatch[3] || '/'
|
toolPath: pvtMatch[3] || '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const psMatch = uri.match(projectToolRe)
|
const ptMatch = uri.match(projectToolRe)
|
||||||
|
|
||||||
if (psMatch) {
|
if (ptMatch) {
|
||||||
return {
|
return {
|
||||||
projectIdentifier: psMatch[1]!,
|
projectIdentifier: ptMatch[1]!,
|
||||||
toolPath: psMatch[2] || '/',
|
toolPath: ptMatch[2] || '/',
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue