added bunch of stuff

This commit is contained in:
Rajpreet0 2026-10-10 02:38:50 +02:00
parent 46a600d3c3
commit 29f5a09557
65 changed files with 5516 additions and 250 deletions

View file

@ -0,0 +1,31 @@
import type { NextRequest } from "next/server"
import { getProfile } from "@/lib/supabase/dal"
import { buildProject } from "@/modules/templates/export/project"
import { resolveContent } from "@/modules/templates/lib/content"
import { getTemplate } from "@/modules/templates/lib/registry"
import { getVariant } from "@/modules/templates/queries/variants"
// Gespeicherter Stand einer Variante als eigenständiges Next.js-Projekt (ZIP) – nur für Admins
export async function GET(_request: NextRequest, ctx: RouteContext<"/api/templates/[id]/export">) {
const profile = await getProfile()
if (profile?.role !== "admin") return Response.json({ error: "Keine Berechtigung." }, { status: 403 })
const { id } = await ctx.params
const variant = await getVariant(id)
const def = variant ? getTemplate(variant.template_key) : undefined
if (!variant || !def) return Response.json({ error: "Variante nicht gefunden." }, { status: 404 })
try {
const { fileName, zip } = await buildProject(def, resolveContent(def, variant.content), variant.name)
return new Response(zip, {
headers: {
"Content-Type": "application/zip",
"Content-Disposition": `attachment; filename="${fileName}"`,
"Cache-Control": "no-store",
},
})
} catch (error) {
console.error("Template export failed:", error)
return Response.json({ error: "Export fehlgeschlagen." }, { status: 500 })
}
}