feat(n11): add base64 document staging from e-Court
เพิ่มทางเข้าเอกสารสำหรับ e-Court ที่ไม่มี URL ให้ดึง — POST /api/note/files/stage (x-api-key DOCVER_API_KEY) ส่งเนื้อไฟล์ PDF/รูปเป็น base64 ระบบเก็บใน RAM staging (TTL sliding 8 ชม. + LRU + cap 100MB/ไฟล์ 256MB รวม — ห้ามเขียน disk/DB/MinIO แม้แต่ไบต์เดียวตามโจทย์) ส่วน annotation/bookmark เก็บถาวรตามระบบเดิม: - lib/staged-docs.ts: Map บน globalThis + sentinel "staged:<uuid>.<ext>" ใน pdf_url (ext จาก magic bytes — ไม่ต้อง migration) + hasStagedDoc แยกจาก getStagedDoc - lib/ecourt-fid.ts: external_id เก็บ HMAC-SHA256(pepper, fid) แทน fid ดิบ (env FID_HASH_PEPPER fail-closed) + แปลง row เก่าด้วย npm run migrate:ecourt-fid - route stage: อ่าน body แบบ stream นับไบต์ + idle 60 วิ/total 10 นาที = 408 + concurrency default 1 = 429 + base64 strict + magic bytes กำหนด ext เอง - registerStagedFile: ลำดับกัน race 23505 — stage ใต้ id ก่อน insert โดนชนแล้ว re-stage ใต้ id ผู้ชนะ + try/finally คืน RAM ผู้แพ้ทุกทางออก - ทางอ่าน 4 จุด: /api/note/pdf + export route (410 gate ไทย), resolvePublicPdfPath guard PdfPathError, PDFViewer โหลดผ่าน route + objectURL (gate ครบทุกชนิดไฟล์) - session route (D5): ลิงก์ fid-only ตัดสิน staging ตั้งแต่แลก token — มี bytes ได้ fileId / หมดอายุ fileError "พ้นช่วงจัดเตรียม" / token ออกทุกกรณี - Swagger UI: endpoint ใหม่ + คู่มือ retry (408/429/5xx ยิงซ้ำได้ stage ซ้ำปลอดภัย) - MockStageForm บน /note/dev ทดสอบ 3 ขั้นในหน้าเดียว (ต้องถือ API key จริง) Verify ครบตาม docs/PLAN-STAGED.md: tsc สะอาด + vitest 59 เคสใหม่ผ่าน + E2E browser จริง (textLayer ไทยเรียงถูก / export ฝัง annotation / restart ได้ fileError ตั้งแต่ bootstrap / RAM 100MB: peak WS +580MB commit จริง +92MB) — ผ่าน code review รอบ 7 แก้ครบทุก finding Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
2e951f99f4
commit
a02e983ba8
34 changed files with 2396 additions and 62 deletions
|
|
@ -4,6 +4,7 @@ import { notFound } from "next/navigation";
|
|||
import AppNav from "@/components/AppNav";
|
||||
import DevLoginLinkForm from "@/components/DevLoginLinkForm";
|
||||
import MockEcourtForm from "@/components/MockEcourtForm";
|
||||
import MockStageForm from "@/components/MockStageForm";
|
||||
import { devMintEnabled } from "@/lib/note-auth";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
|
@ -149,6 +150,26 @@ export default async function DevToolsPage({
|
|||
<MockEcourtForm files={Object.values(SAMPLE_DOCS).flat()} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* จำลอง e-Court แบบ base64 staging (N11 — คำขอผู้ใช้ 2026-11-04): ให้ dev
|
||||
ฝั่ง e-Court กดทดสอบ contract ทั้ง 3 ขั้นในหน้าเดียว — stage → mint →
|
||||
ลิงก์ fid-only · ต้องถือ DOCVER_API_KEY จริงจึงไม่ใช่ประตูหลัง */}
|
||||
<div className="mt-5 max-w-xl rounded-xl border border-line bg-white p-6">
|
||||
<h3 className="font-display text-subhead text-primary">
|
||||
จำลอง e-Court — ส่งเนื้อไฟล์เข้า staging (base64)
|
||||
</h3>
|
||||
<p className="mt-1.5 text-sm text-ink-soft">
|
||||
สำหรับเอกสารที่ e-Court <strong className="font-medium">ไม่มี URL ให้ดึง</strong> —
|
||||
เลือกไฟล์แล้วกดปุ่มเดียว ระบบจะทำตาม contract จริงทั้ง 3 ขั้น:{" "}
|
||||
<Code>POST /api/note/files/stage</Code> (เนื้อไฟล์เป็น base64) →{" "}
|
||||
<Code>POST /api/note/auth/token</Code> ด้วย <Code>fid</Code> เดิม → ลิงก์{" "}
|
||||
<Code>/note?t=…</Code> (ไม่มี fileUrl) ให้กดเข้าอ่านได้เลย · ส่ง{" "}
|
||||
<Code>fid</Code> เดิมซ้ำ = แทนที่เนื้อล่าสุด (annotation เดิมอยู่ครบ)
|
||||
</p>
|
||||
<div className="mt-4">
|
||||
<MockStageForm />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── Flow ─────────────────────────────────────────────────────────── */}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue