Complete admin panel for content management: - SQLite database with better-sqlite3, seed script from content.ts - Simple password auth with HMAC-signed cookies (Edge + Node compatible) - 9 section editors: meta, hero, about, team, classes, schedule, pricing, FAQ, contact - Team CRUD with image upload and drag reorder - Schedule editor with Google Calendar-style visual timeline (colored blocks, overlap detection, click-to-add) - All public components refactored to accept data props from DB (with fallback to static content) - Middleware protecting /admin/* and /api/admin/* routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getSection, setSection, SECTION_KEYS } from "@/lib/db";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
type Params = { params: Promise<{ key: string }> };
|
|
|
|
export async function GET(_request: NextRequest, { params }: Params) {
|
|
const { key } = await params;
|
|
if (!SECTION_KEYS.includes(key as typeof SECTION_KEYS[number])) {
|
|
return NextResponse.json({ error: "Invalid section key" }, { status: 400 });
|
|
}
|
|
|
|
const data = getSection(key);
|
|
if (!data) {
|
|
return NextResponse.json({ error: "Section not found" }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json(data);
|
|
}
|
|
|
|
export async function PUT(request: NextRequest, { params }: Params) {
|
|
const { key } = await params;
|
|
if (!SECTION_KEYS.includes(key as typeof SECTION_KEYS[number])) {
|
|
return NextResponse.json({ error: "Invalid section key" }, { status: 400 });
|
|
}
|
|
|
|
const data = await request.json();
|
|
setSection(key, data);
|
|
revalidatePath("/");
|
|
|
|
return NextResponse.json({ ok: true });
|
|
}
|