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:
chaloemphong
2026-11-22 11:52:17 +07:00
commit 9d32552457
155 changed files with 22174 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import { NextResponse } from "next/server";
import { putLocalBlob } from "@/lib/storage/local-blob";
import { requirePageAction } from "@/lib/auth/user";
import { errorResponse } from "@/lib/http";
const MAX_BYTES = 8 * 1024 * 1024; // Facebook photo limit is ~10MB; IG JPEG ≤ 8MB
const ALLOWED = ["image/jpeg", "image/png"];
/**
* Uploads a post image to disk as a public, unguessable URL (served by
* `/api/uploads/[...path]`). Meta's servers fetch it directly for FB `url=`
* photo posts and IG containers, so no signed asset route is needed.
*/
export async function POST(req: Request) {
const form = await req.formData().catch(() => null);
const pageId = form?.get("pageId");
const file = form?.get("file");
if (typeof pageId !== "string" || !(file instanceof File)) {
return NextResponse.json({ error: "ไม่พบไฟล์" }, { status: 400 });
}
const auth = await requirePageAction(pageId, "editPost");
if (!auth.ok) return auth.response;
if (!ALLOWED.includes(file.type)) return NextResponse.json({ error: "รองรับเฉพาะ JPG และ PNG" }, { status: 400 });
if (file.size > MAX_BYTES) return NextResponse.json({ error: "ไฟล์ใหญ่เกิน 8MB" }, { status: 400 });
try {
const ext = file.type === "image/png" ? "png" : "jpg";
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || new URL(req.url).origin;
const blob = await putLocalBlob(`posts/${pageId}/image.${ext}`, file, { contentType: file.type }, baseUrl);
return NextResponse.json({ url: blob.url });
} catch (e) {
return errorResponse(e, "upload");
}
}