feat: complete v0.5 operations foundation

This commit is contained in:
2026-07-19 03:58:03 +08:00
parent ca3f706cc1
commit d285f3e275
35 changed files with 248 additions and 39 deletions
+17
View File
@@ -0,0 +1,17 @@
import { NextResponse } from "next/server";
import { requireUser } from "@/lib/auth";
import { db } from "@/lib/db";
import { externalUrl } from "@/lib/http";
import { requireSameOrigin } from "@/lib/security";
export async function POST(request: Request) {
try {
requireSameOrigin(request); const user = await requireUser(); const form = await request.formData();
const postId = Number(form.get("postId")); const reason = String(form.get("reason") || "").trim();
if (!postId || reason.length < 3 || reason.length > 500) throw new Error("Invalid report");
const post = db.prepare("SELECT id FROM posts WHERE id=? AND hidden=0").get(postId);
if (!post) throw new Error("Post not found");
db.prepare("INSERT INTO reports(post_id,reporter_id,reason) SELECT ?,?,? WHERE NOT EXISTS (SELECT 1 FROM reports WHERE post_id=? AND reporter_id=? AND resolved=0)").run(postId, user.id, reason, postId, user.id);
return NextResponse.redirect(externalUrl(request, `/posts/${postId}?reported=1`));
} catch { return NextResponse.redirect(externalUrl(request, "/")); }
}