mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 20:51:17 +00:00
added bunch of stuff
This commit is contained in:
parent
46a600d3c3
commit
29f5a09557
65 changed files with 5516 additions and 250 deletions
31
app/api/templates/[id]/export/route.ts
Normal file
31
app/api/templates/[id]/export/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue