kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
61cb19b381
commit
35ff518ff7
|
@ -1,8 +1,9 @@
|
||||||
import type { DefaultHonoEnv } from '@agentic/platform-hono'
|
import type { DefaultHonoEnv } from '@agentic/platform-hono'
|
||||||
import { assert, parseZodSchema } from '@agentic/platform-core'
|
import { parseZodSchema } from '@agentic/platform-core'
|
||||||
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { db, eq, schema } from '@/db'
|
import { db, eq, schema } from '@/db'
|
||||||
|
import { aclPublicProject } from '@/lib/acl-public-project'
|
||||||
import {
|
import {
|
||||||
openapiAuthenticatedSecuritySchemas,
|
openapiAuthenticatedSecuritySchemas,
|
||||||
openapiErrorResponse404,
|
openapiErrorResponse404,
|
||||||
|
@ -49,11 +50,7 @@ export function registerV1GetPublicProjectByIdentifier(
|
||||||
...Object.fromEntries(populate.map((field) => [field, true]))
|
...Object.fromEntries(populate.map((field) => [field, true]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
assert(
|
await aclPublicProject(project, projectIdentifier)
|
||||||
project && !project.private && project.lastPublishedDeploymentId,
|
|
||||||
404,
|
|
||||||
`Public project not found "${projectIdentifier}"`
|
|
||||||
)
|
|
||||||
|
|
||||||
return c.json(parseZodSchema(schema.projectSelectSchema, project))
|
return c.json(parseZodSchema(schema.projectSelectSchema, project))
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import type { DefaultHonoEnv } from '@agentic/platform-hono'
|
import type { DefaultHonoEnv } from '@agentic/platform-hono'
|
||||||
import { assert, parseZodSchema } from '@agentic/platform-core'
|
import { parseZodSchema } from '@agentic/platform-core'
|
||||||
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { db, eq, schema } from '@/db'
|
import { db, eq, schema } from '@/db'
|
||||||
|
import { aclPublicProject } from '@/lib/acl-public-project'
|
||||||
import {
|
import {
|
||||||
openapiAuthenticatedSecuritySchemas,
|
openapiAuthenticatedSecuritySchemas,
|
||||||
openapiErrorResponse404,
|
openapiErrorResponse404,
|
||||||
|
@ -48,11 +49,7 @@ export function registerV1GetPublicProject(app: OpenAPIHono<DefaultHonoEnv>) {
|
||||||
...Object.fromEntries(populate.map((field) => [field, true]))
|
...Object.fromEntries(populate.map((field) => [field, true]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
assert(
|
await aclPublicProject(project, projectId)
|
||||||
project && !project.private && project.lastPublishedDeploymentId,
|
|
||||||
404,
|
|
||||||
`Public project not found "${projectId}"`
|
|
||||||
)
|
|
||||||
|
|
||||||
return c.json(parseZodSchema(schema.projectSelectSchema, project))
|
return c.json(parseZodSchema(schema.projectSelectSchema, project))
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { assert } from '@agentic/platform-core'
|
||||||
|
|
||||||
|
import type { RawProject } from '@/db'
|
||||||
|
|
||||||
|
export async function aclPublicProject(
|
||||||
|
project: RawProject | undefined,
|
||||||
|
projectId?: string
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
project,
|
||||||
|
404,
|
||||||
|
`Public project not found${projectId ? ` "${projectId}"` : ''}`
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
!project.private && project.lastPublishedDeploymentId,
|
||||||
|
404,
|
||||||
|
`Public project not found "${project.id}"`
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(!project.deletedAt, 410, `Project has been deleted "${project.id}"`)
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import { upsertStripeCustomer } from '@/lib/billing/upsert-stripe-customer'
|
||||||
import { upsertStripePricing } from '@/lib/billing/upsert-stripe-pricing'
|
import { upsertStripePricing } from '@/lib/billing/upsert-stripe-pricing'
|
||||||
import { createConsumerToken } from '@/lib/create-consumer-token'
|
import { createConsumerToken } from '@/lib/create-consumer-token'
|
||||||
|
|
||||||
|
import { aclPublicProject } from '../acl-public-project'
|
||||||
import { createStripeCheckoutSession } from '../billing/create-stripe-checkout-session'
|
import { createStripeCheckoutSession } from '../billing/create-stripe-checkout-session'
|
||||||
|
|
||||||
export async function upsertConsumerStripeCheckout(
|
export async function upsertConsumerStripeCheckout(
|
||||||
|
@ -65,12 +66,6 @@ export async function upsertConsumerStripeCheckout(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
assert(deployment, 404, `Deployment not found "${deploymentId}"`)
|
assert(deployment, 404, `Deployment not found "${deploymentId}"`)
|
||||||
assert(
|
|
||||||
!deployment.deletedAt,
|
|
||||||
410,
|
|
||||||
`Deployment has been deleted by its owner "${deployment.id}"`
|
|
||||||
)
|
|
||||||
await acl(c, deployment, { label: 'Deployment' })
|
|
||||||
|
|
||||||
project = deployment.project!
|
project = deployment.project!
|
||||||
assert(
|
assert(
|
||||||
|
@ -78,7 +73,16 @@ export async function upsertConsumerStripeCheckout(
|
||||||
404,
|
404,
|
||||||
`Project not found "${projectId}" for deployment "${deploymentId}"`
|
`Project not found "${projectId}" for deployment "${deploymentId}"`
|
||||||
)
|
)
|
||||||
await acl(c, project, { label: 'Project' })
|
await aclPublicProject(project)
|
||||||
|
|
||||||
|
// Validate the deployment only after we're sure the project is publicly
|
||||||
|
// accessible.
|
||||||
|
assert(
|
||||||
|
!deployment.deletedAt,
|
||||||
|
410,
|
||||||
|
`Deployment has been deleted by its owner "${deployment.id}"`
|
||||||
|
)
|
||||||
|
|
||||||
projectId = project.id
|
projectId = project.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,8 @@ export function MarketplaceIndex() {
|
||||||
<p>Error fetching projects</p>
|
<p>Error fetching projects</p>
|
||||||
) : !projects.length ? (
|
) : !projects.length ? (
|
||||||
<p>
|
<p>
|
||||||
No projects found. Create your first project to get started!
|
No projects found. This is likely an error on Agentic's side.
|
||||||
|
Please refresh or contact support.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className='grid gap-4'>
|
<div className='grid gap-4'>
|
||||||
|
|
|
@ -33,7 +33,9 @@ export async function toastError(
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(...[ctx?.label, message, details].filter(Boolean))
|
console.error(...[ctx?.label, message, details].filter(Boolean))
|
||||||
toastImpl.error(message)
|
toastImpl.error(message, {
|
||||||
|
duration: 10_000
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { toast } from 'sonner'
|
export { toast } from 'sonner'
|
||||||
|
|
|
@ -347,7 +347,9 @@ export class AgenticApiClient {
|
||||||
} = {}
|
} = {}
|
||||||
): Promise<Array<PopulateProject<TPopulate>>> {
|
): Promise<Array<PopulateProject<TPopulate>>> {
|
||||||
return this.ky
|
return this.ky
|
||||||
.get('v1/projects', { searchParams: sanitizeSearchParams(searchParams) })
|
.get('v1/projects/public', {
|
||||||
|
searchParams: sanitizeSearchParams(searchParams)
|
||||||
|
})
|
||||||
.json()
|
.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue