Initial commit: page-manager Next.js app with Coolify deploy support
Replace Vercel-specific infra (Cron, Blob) with self-hosted equivalents for deployment to Coolify: in-container cron scheduler (scripts/cron-runner.mjs) and disk-based upload storage served via /api/uploads/[...path]. Add Dockerfile, .dockerignore, and /api/health for container health checks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireUser, actorLabel } from "@/lib/auth/user";
|
||||
import { audit } from "@/lib/audit";
|
||||
import { errorResponse } from "@/lib/http";
|
||||
import { accountProfileSchema, prepareAvatar } from "@/lib/account-profile";
|
||||
|
||||
export async function PUT(req: Request) {
|
||||
const auth = await requireUser();
|
||||
if (!auth.ok) return auth.response;
|
||||
const form = await req.formData().catch(() => null);
|
||||
if (!form) return NextResponse.json({ error: "ข้อมูลไม่ถูกต้อง" }, { status: 400 });
|
||||
const parsed = accountProfileSchema.safeParse({ name: form.get("name"), bio: form.get("bio") });
|
||||
if (!parsed.success) return NextResponse.json({ error: parsed.error.issues[0].message }, { status: 400 });
|
||||
|
||||
let avatarUrl: string | null | undefined;
|
||||
const avatar = form.get("avatar");
|
||||
if (form.get("removeAvatar") === "true") avatarUrl = null;
|
||||
else if (avatar instanceof File && avatar.size) {
|
||||
try {
|
||||
avatarUrl = await prepareAvatar(avatar);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: (error as Error).message }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await tx.user.update({ where: { id: auth.user.id }, data: { ...parsed.data, avatarUrl } });
|
||||
await audit({
|
||||
action: "USER_UPDATED", actorId: auth.user.id, actorLabel: actorLabel(auth.user),
|
||||
detail: { userId: auth.user.id, fields: ["name", "bio", ...(avatarUrl !== undefined ? ["avatarUrl"] : [])] },
|
||||
}, tx);
|
||||
});
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
return errorResponse(error, "บันทึกโปรไฟล์ไม่สำเร็จ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user