From d103af162da2e81f27ed1407cc3be80d98d1efbe Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Thu, 6 Nov 2025 07:34:34 +0000 Subject: [PATCH] completionId: cgen-5a6d4c2b4a06420e823bc98045e51a02 cgen-5a6d4c2b4a06420e823bc98045e51a02 --- netlify/functions/api.ts | 4 - netlify/functions/sync-docs-to-gitbook.ts | 124 ---------------------- 2 files changed, 128 deletions(-) delete mode 100644 netlify/functions/api.ts delete mode 100644 netlify/functions/sync-docs-to-gitbook.ts diff --git a/netlify/functions/api.ts b/netlify/functions/api.ts deleted file mode 100644 index 63485673..00000000 --- a/netlify/functions/api.ts +++ /dev/null @@ -1,4 +0,0 @@ -import serverless from "serverless-http"; -import { createServer } from "../../server"; - -export const handler = serverless(createServer()); diff --git a/netlify/functions/sync-docs-to-gitbook.ts b/netlify/functions/sync-docs-to-gitbook.ts deleted file mode 100644 index 2d2fbe79..00000000 --- a/netlify/functions/sync-docs-to-gitbook.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { Handler } from "@netlify/functions"; -import { readFileSync } from "fs"; -import { join } from "path"; - -const GITBOOK_API_TOKEN = - process.env.GITBOOK_API_TOKEN || - "gb_api_jORqpp2qlvg7pwlPiIKHAbgcFIDJBIJ1pz09WpIg"; -const GITBOOK_SPACE_ID = process.env.GITBOOK_SPACE_ID || "37ITJTgjD56eN3ZI5qtt"; - -const PAGES = [ - { - title: "Welcome to AeThex Documentation", - slug: "overview", - file: "01-overview.md", - }, - { - title: "Getting Started", - slug: "getting-started", - file: "02-getting-started.md", - }, - { title: "Platform Guide", slug: "platform", file: "03-platform.md" }, - { - title: "API Reference", - slug: "api-reference", - file: "04-api-reference.md", - }, - { title: "Tutorials", slug: "tutorials", file: "05-tutorials.md" }, - { title: "CLI Tools", slug: "cli", file: "06-cli.md" }, - { title: "Code Examples", slug: "examples", file: "07-examples.md" }, - { title: "Integrations", slug: "integrations", file: "08-integrations.md" }, - { title: "Curriculum", slug: "curriculum", file: "09-curriculum.md" }, -]; - -async function makeRequest( - method: string, - path: string, - body?: any, -): Promise { - const response = await fetch(`https://api.gitbook.com/v1${path}`, { - method, - headers: { - Authorization: `Bearer ${GITBOOK_API_TOKEN}`, - "Content-Type": "application/json", - "User-Agent": "AeThex-Docs-Sync", - }, - body: body ? JSON.stringify(body) : undefined, - }); - - if (!response.ok) { - throw new Error(`API Error: ${response.status} ${response.statusText}`); - } - - return response.json(); -} - -const handler: Handler = async (event, context) => { - // Basic auth check - const authHeader = event.headers["authorization"]; - const expectedAuth = `Bearer ${process.env.SYNC_TOKEN || "aethex-docs-sync"}`; - - if (authHeader !== expectedAuth) { - return { - statusCode: 401, - body: JSON.stringify({ error: "Unauthorized" }), - }; - } - - try { - const results = []; - let successful = 0; - let failed = 0; - - for (const page of PAGES) { - try { - // Read markdown file from docs-migration directory - const filePath = join( - process.cwd(), - "..", - "..", - "docs-migration", - page.file, - ); - const content = readFileSync(filePath, "utf-8"); - - const body = { - title: page.title, - description: `AeThex Documentation - ${page.title}`, - }; - - await makeRequest("POST", `/spaces/${GITBOOK_SPACE_ID}/pages`, body); - results.push({ page: page.title, status: "success" }); - successful++; - } catch (error) { - const errorMessage = - error instanceof Error ? error.message : "Unknown error"; - results.push({ - page: page.title, - status: "failed", - error: errorMessage, - }); - failed++; - } - } - - return { - statusCode: 200, - body: JSON.stringify({ - message: "Sync complete", - successful, - failed, - results, - }), - }; - } catch (error) { - const errorMessage = - error instanceof Error ? error.message : "Unknown error"; - return { - statusCode: 500, - body: JSON.stringify({ error: errorMessage }), - }; - } -}; - -export { handler };