feat: full site build — Project/Melody schema (Option A), admin CRUD, public sections, uploads, email+SMTP, internal analytics, legal pages, docs
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { headers } from "next/headers";
|
||||
import { recordAnalyticsEvent } from "@/lib/analytics";
|
||||
import { consumeRateLimit, getClientIp } from "@/lib/rate-limit";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const ip = getClientIp(headers());
|
||||
if (!consumeRateLimit(`analytics:${ip}`, 60, 60 * 1000)) {
|
||||
return NextResponse.json({ error: "rate-limited" }, { status: 429 });
|
||||
}
|
||||
|
||||
try {
|
||||
const input = await request.json();
|
||||
const recorded = await recordAnalyticsEvent(input);
|
||||
return recorded ? new NextResponse(null, { status: 204 }) : NextResponse.json({ error: "invalid-event" }, { status: 400 });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "invalid-request" }, { status: 400 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { handlers } from "@/lib/auth";
|
||||
|
||||
export const { GET, POST } = handlers;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { saveUploadedFile, UploadError } from "@/lib/upload";
|
||||
import { uploadKindSchema } from "@/lib/validations/upload";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Unauthorized." }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
const kindResult = uploadKindSchema.safeParse(formData.get("kind"));
|
||||
const file = formData.get("file");
|
||||
|
||||
if (!kindResult.success || !(file instanceof File)) {
|
||||
return NextResponse.json({ error: "A valid upload kind and file are required." }, { status: 400 });
|
||||
}
|
||||
|
||||
const uploadedFile = await saveUploadedFile(file, kindResult.data);
|
||||
return NextResponse.json(uploadedFile, { status: 201 });
|
||||
} catch (error) {
|
||||
if (error instanceof UploadError) {
|
||||
return NextResponse.json({ error: error.message }, { status: error.statusCode });
|
||||
}
|
||||
|
||||
console.error("Upload failed", error);
|
||||
return NextResponse.json({ error: "The file could not be uploaded." }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user