Pages list and Tiptap editor (ported from babyboo) with image upload on save, the FORM event picker, field errors at their fields, delete confirmation, unsaved-edits guard and a draft preview. The public page /p/<company>/<slug> renders on the server with metadata, sanitize-html, the company's logo and accent, and the sign-up form with UTM tags. Companies get branding; the event lead detail shows the web page and campaign. Labels in English and Chinese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { callMobileApi } from "@/app/lib/server/mobileApi";
|
|
import { getToken } from "@/app/lib/server/session";
|
|
import { errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
const params = new URL(req.url).searchParams;
|
|
const qs = new URLSearchParams();
|
|
const q = params.get("q");
|
|
if (q) qs.set("q", q);
|
|
const companyId = params.get("companyId");
|
|
if (companyId && /^\d+$/.test(companyId)) qs.set("companyId", companyId);
|
|
for (const k of ["page", "size"]) {
|
|
const v = params.get(k);
|
|
if (v && /^\d+$/.test(v)) qs.set(k, v);
|
|
}
|
|
const result = await callMobileApi<Record<string, unknown>>(`/api/admin/pages?${qs.toString()}`, { token });
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const token = await getToken();
|
|
if (!token) return unauthorized();
|
|
const body = await req.json().catch(() => ({}));
|
|
const result = await callMobileApi<Record<string, unknown>>("/api/admin/pages", { method: "POST", body, token });
|
|
if (!result.ok) return errorResponse(result);
|
|
return NextResponse.json(result.data);
|
|
}
|