7.5 추천/신고, 조회수 카운트 o

This commit is contained in:
koreacomp5
2025-10-09 17:05:19 +09:00
parent 60d7972762
commit 6d37881dd7
7 changed files with 97 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { getUserIdFromRequest } from "@/lib/auth";
export async function POST(req: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const userId = getUserIdFromRequest(req);
const ip = req.headers.get("x-forwarded-for") || undefined;
const userAgent = req.headers.get("user-agent") || undefined;
await prisma.postViewLog.create({ data: { postId: id, userId: userId ?? null, ip, userAgent } });
await prisma.postStat.upsert({ where: { postId: id }, update: { views: { increment: 1 } }, create: { postId: id, views: 1 } });
return NextResponse.json({ ok: true });
}

View File

@@ -0,0 +1,24 @@
import { NextResponse } from "next/server";
import { promises as fs } from "fs";
import path from "path";
export const runtime = "nodejs";
export async function POST(req: Request) {
const form = await req.formData();
const file = form.get("file") as File | null;
if (!file) return NextResponse.json({ error: "file required" }, { status: 400 });
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
const ext = path.extname(file.name || "") || ".bin";
const uploadsDir = path.join(process.cwd(), "public", "uploads");
await fs.mkdir(uploadsDir, { recursive: true });
const filename = `${Date.now()}-${Math.random().toString(36).slice(2)}${ext}`;
const filepath = path.join(uploadsDir, filename);
await fs.writeFile(filepath, buffer);
const url = `/uploads/${filename}`;
return NextResponse.json({ url });
}