import Link from "next/link"; import { redirect } from "next/navigation"; import { registerExternalFile } from "@/lib/external-import"; import { firstSearchParam } from "@/utils/external-file"; export const dynamic = "force-dynamic"; /** * N8 entry point ที่สอง (ตามคำขอผู้ใช้ 2026-09-22): เข้า `/note/annotate?fileUrl=&fileId=&typeId=` * โดยตรง — ลงทะเบียนเอกสารแล้ว redirect ต่อไป `/note/annotate/` ของตัว viewer จริง * (entry เดิมที่หน้า "/note" ยังใช้ได้คู่กัน — สัญญาลิงก์รับทั้ง /note?fileUrl= และ /note/annotate?fileUrl=) */ export default async function AnnotateEntryPage({ searchParams, }: { searchParams: Record; }) { const fileUrl = firstSearchParam(searchParams.fileUrl); if (fileUrl) { const result = await registerExternalFile( fileUrl, firstSearchParam(searchParams.fileId), firstSearchParam(searchParams.typeId), ); // redirect โยน NEXT_REDIRECT — เรียกนอก try/catch เสมอ if (result.ok) redirect(`/note/annotate/${result.fileId}`); return (
เปิดเอกสารจากลิงก์ไม่สำเร็จ: {result.error}
กลับหน้ารายการ
); } // ไม่มี fileUrl เลย — ไม่มีอะไรให้เปิด (route จริงของ viewer อยู่ที่ /note/annotate/[id]) return (
ไม่ได้ระบุลิงก์เอกสาร — ใช้ /annotate?fileUrl=…&fileId=…&typeId=… {" "} หรือเลือกไฟล์จากหน้ารายการ
กลับหน้ารายการ
); }