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 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'
|
||||
|
||||
/**
|
||||
|
@ -63,52 +70,65 @@ export async function tryGetDeploymentByIdentifier(
|
|||
assert(deployment, 404, `Deployment not found "${deploymentIdentifier}"`)
|
||||
|
||||
return deployment
|
||||
} else if (version === 'latest') {
|
||||
} else if (version) {
|
||||
const project = await db.query.projects.findFirst({
|
||||
...dbQueryOpts,
|
||||
where: eq(schema.projects.identifier, projectIdentifier)
|
||||
})
|
||||
assert(project, 404, `Project not found "${projectIdentifier}"`)
|
||||
assert(
|
||||
project.lastPublishedDeploymentId,
|
||||
404,
|
||||
'Project has no published deployments'
|
||||
)
|
||||
|
||||
const deployment = await db.query.deployments.findFirst({
|
||||
...dbQueryOpts,
|
||||
where: eq(schema.deployments.id, project.lastPublishedDeploymentId)
|
||||
})
|
||||
assert(
|
||||
deployment,
|
||||
404,
|
||||
`Deployment not found "${project.lastPublishedDeploymentId}"`
|
||||
)
|
||||
if (version === 'latest') {
|
||||
assert(
|
||||
project.lastPublishedDeploymentId,
|
||||
404,
|
||||
'Project has no published deployments'
|
||||
)
|
||||
|
||||
return deployment
|
||||
} else if (version === 'dev') {
|
||||
const project = await db.query.projects.findFirst({
|
||||
...dbQueryOpts,
|
||||
where: eq(schema.projects.id, projectIdentifier)
|
||||
})
|
||||
assert(project, 404, `Project not found "${projectIdentifier}"`)
|
||||
assert(
|
||||
project.lastDeploymentId,
|
||||
404,
|
||||
'Project has no published deployments'
|
||||
)
|
||||
const deployment = await db.query.deployments.findFirst({
|
||||
...dbQueryOpts,
|
||||
where: eq(schema.deployments.id, project.lastPublishedDeploymentId)
|
||||
})
|
||||
assert(
|
||||
deployment,
|
||||
404,
|
||||
`Deployment not found "${project.lastPublishedDeploymentId}"`
|
||||
)
|
||||
|
||||
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 if (version === 'dev') {
|
||||
assert(
|
||||
project.lastDeploymentId,
|
||||
404,
|
||||
'Project has no published deployments'
|
||||
)
|
||||
|
||||
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}"`)
|
||||
|
|
|
@ -19,12 +19,12 @@ const projectToolRe =
|
|||
/^([a-zA-Z0-9-]{1,64}\/[a-z0-9-]{2,64})(\/[a-zA-Z0-9\-._~%!$&'()*+,;=:/]*)?$/
|
||||
|
||||
export function parseFaasUri(uri: string): ParsedFaasIdentifier | undefined {
|
||||
const pdsMatch = uri.match(projectDeploymentToolRe)
|
||||
const pdtMatch = uri.match(projectDeploymentToolRe)
|
||||
|
||||
if (pdsMatch) {
|
||||
const projectIdentifier = pdsMatch[1]!
|
||||
const deploymentHash = pdsMatch[2]!
|
||||
const toolPath = pdsMatch[3] || '/'
|
||||
if (pdtMatch) {
|
||||
const projectIdentifier = pdtMatch[1]!
|
||||
const deploymentHash = pdtMatch[2]!
|
||||
const toolPath = pdtMatch[3] || '/'
|
||||
|
||||
return {
|
||||
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 {
|
||||
projectIdentifier: pvsMatch[1]!,
|
||||
version: pvsMatch[2]!,
|
||||
toolPath: pvsMatch[3] || '/'
|
||||
projectIdentifier: pvtMatch[1]!,
|
||||
version: pvtMatch[2]!,
|
||||
toolPath: pvtMatch[3] || '/'
|
||||
}
|
||||
}
|
||||
|
||||
const psMatch = uri.match(projectToolRe)
|
||||
const ptMatch = uri.match(projectToolRe)
|
||||
|
||||
if (psMatch) {
|
||||
if (ptMatch) {
|
||||
return {
|
||||
projectIdentifier: psMatch[1]!,
|
||||
toolPath: psMatch[2] || '/',
|
||||
projectIdentifier: ptMatch[1]!,
|
||||
toolPath: ptMatch[2] || '/',
|
||||
version: 'latest'
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue