Files
pbakaus_impeccable/functions/api/download/bundle/[provider].js
T
Paul BakausandClaude Opus 4.6 7d2d42da96 Migrate from Vercel to Cloudflare Pages, fix distill command symbol
Replace Vercel serverless functions with Cloudflare Pages static
rewrites and lightweight download functions. Pre-generate all API
JSON data at build time for zero-invocation static serving. Also
fix stale simplify→distill rename in framework-viz periodic table.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:34:14 -07:00

30 lines
898 B
JavaScript

const ALLOWED_PROVIDERS = ['universal', 'universal-prefixed'];
export async function onRequestGet(context) {
const { provider } = context.params;
if (!provider || !ALLOWED_PROVIDERS.includes(provider)) {
return Response.json({ error: "Invalid provider" }, { status: 400 });
}
const url = new URL(context.request.url);
url.pathname = `/_data/dist/${provider}.zip`;
const response = await context.env.ASSETS.fetch(url);
if (!response.ok) {
return Response.json({ error: "Bundle not found" }, { status: 404 });
}
const content = await response.arrayBuffer();
const safeProvider = provider.replace(/[^a-zA-Z0-9._-]/g, '');
return new Response(content, {
headers: {
'Content-Type': 'application/zip',
'Content-Disposition': `attachment; filename="impeccable-style-${safeProvider}.zip"`,
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=3600',
}
});
}