Git history was lost when the previous Gitea instance was wiped and reinstalled due to an unresolved corruption bug — this commit is the last known-good file content, exported before the reinstall. Prior commit history is not recoverable through this path.
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
export const runtime = "nodejs";
|
|
|
|
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { requireSession } from "@/lib/auth/require";
|
|
import { listCannedResponses, createCannedResponse } from "@/lib/tickets/service";
|
|
|
|
export async function GET() {
|
|
const { session, response } = await requireSession();
|
|
if (!session) return response;
|
|
|
|
return NextResponse.json({ responses: await listCannedResponses() });
|
|
}
|
|
|
|
const createSchema = z.object({
|
|
title: z.string().min(1).max(100),
|
|
body: z.string().min(1).max(5_000),
|
|
});
|
|
|
|
export async function POST(request: Request) {
|
|
const { session, response } = await requireSession();
|
|
if (!session) return response;
|
|
|
|
const body = await request.json().catch(() => null);
|
|
const parsed = createSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: "Invalid input" }, { status: 400 });
|
|
}
|
|
|
|
const canned = await createCannedResponse(parsed.data.title, parsed.data.body);
|
|
return NextResponse.json({ response: canned }, { status: 201 });
|
|
}
|