Skip to content

Commit 5018051

Browse files
committed
fix import cycle
1 parent d39668f commit 5018051

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

website/src/lib/spiceflow-public-api.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@ import { assetsFromFilesList, syncSite } from './sync'
99
import { defaultDocsJsonComments } from 'docs-website/src/lib/docs-json-examples'
1010
import { DocsJsonType } from 'docs-website/src/lib/docs-json'
1111
import { CloudflareClient, getZoneIdForDomain } from './cloudflare'
12-
import { filesSchema } from './spiceflow'
12+
1313
import { client as searchApi } from 'docs-website/src/lib/search-api'
1414

15+
// Export schemas for reuse
16+
export const filesSchema = z.array(
17+
z.object({
18+
relativePath: z.string(),
19+
contents: z.string(),
20+
downloadUrl: z.string().optional(),
21+
metadata: z
22+
.object({
23+
width: z.number().optional(),
24+
height: z.number().optional(),
25+
})
26+
.optional(),
27+
}),
28+
)
29+
1530
export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
1631
.state('apiKey', '')
1732
.state('userId', '')
@@ -20,7 +35,7 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
2035
.use(openapi())
2136
.use(async ({ request, state }, next) => {
2237
const apiKey = request.headers.get('x-api-key')
23-
38+
2439
if (!apiKey) {
2540
return new Response(JSON.stringify({ error: 'API key required' }), {
2641
status: 401,
@@ -76,7 +91,7 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
7691
async handler({ request, state }) {
7792
const body = await request.json()
7893
const { name, orgId, files, githubOwner, githubRepo, githubRepoId, githubBranch, githubFolder } = body
79-
94+
8095
const userOrgAccess = await prisma.orgsUsers.findFirst({
8196
where: {
8297
userId: state.userId,
@@ -555,18 +570,18 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
555570
})
556571
.onError(({ error, request }) => {
557572
notifyError(error, `Public API error: ${request.method} ${request.url}`)
558-
573+
559574
if (error instanceof AppError) {
560575
return new Response(JSON.stringify({ error: error.message }), {
561576
status: 400,
562577
headers: { 'Content-Type': 'application/json' }
563578
})
564579
}
565-
580+
566581
return new Response(JSON.stringify({ error: 'Internal server error' }), {
567582
status: 500,
568583
headers: { 'Content-Type': 'application/json' }
569584
})
570585
})
571586

572-
export type PublicApiApp = typeof publicApiApp
587+
export type PublicApiApp = typeof publicApiApp

website/src/lib/spiceflow.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,9 @@ import { DocsJsonType } from 'docs-website/src/lib/docs-json'
2222
import { openai } from '@ai-sdk/openai'
2323
import { experimental_transcribe as transcribe } from 'ai'
2424
import { applyJsonCComments } from './json-c-comments'
25-
import { publicApiApp } from './spiceflow-public-api'
26-
27-
// Export schemas for reuse
28-
export const filesSchema = z.array(
29-
z.object({
30-
relativePath: z.string(),
31-
contents: z.string(),
32-
downloadUrl: z.string().optional(),
33-
metadata: z
34-
.object({
35-
width: z.number().optional(),
36-
height: z.number().optional(),
37-
})
38-
.optional(),
39-
}),
40-
)
25+
import { filesSchema, publicApiApp } from './spiceflow-public-api'
26+
27+
4128

4229
// Utility to get client IP from request, handling Cloudflare proxy headers
4330
function getClientIp(request: Request): string {
@@ -985,13 +972,13 @@ export const app = new Spiceflow({ basePath: '/api' })
985972
githubBranch: githubBranch || 'main',
986973
files, // Pass the files directly
987974
})
988-
975+
989976
finalSiteId = result.siteId
990977
finalBranchId = result.branchId
991978
}
992979

993980
let pageCount: number
994-
981+
995982
// For updates (existing sites), we need to sync again
996983
if (siteId) {
997984
// Fetch the branch's latest docsJson
@@ -1000,7 +987,7 @@ export const app = new Spiceflow({ basePath: '/api' })
1000987
})
1001988
const docsJson = branch?.docsJson as DocsJsonType
1002989
const docsJsonComments = branch?.docsJsonComments as any
1003-
990+
1004991
// Convert files to pages format
1005992
const assets = assetsFromFilesList({
1006993
files,
@@ -1063,7 +1050,7 @@ export const app = new Spiceflow({ basePath: '/api' })
10631050

10641051
// Get docsJsonComments from the branch
10651052
const branchDocsJsonComments = (branch?.docsJsonComments || {}) as any
1066-
1053+
10671054
const docsJsonWithComments = applyJsonCComments(branch?.docsJson || {}, {
10681055
...defaultDocsJsonComments,
10691056
...branchDocsJsonComments,

0 commit comments

Comments
 (0)