ecourt+groups: N8 เปิดเอกสารจากลิงก์ ?fileUrl=&fileId=&typeId= (metadata-only + allowlist + ดึงไฟล์สด + login วนกลับ + การ์ดจำลองลิงก์ + path dev /samples) + N9 กลุ่มเอกสารตาม typeId — หน้ารายการจัด section ต่อกลุ่ม + "ไม่มีกลุ่ม" ท้ายสุด + หน้า /groups/[typeId] พร้อมหมายเหตุ "อาจไม่ครบทุกฉบับ" + docs sync ครบ (2026-09-23)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-09-23 10:44:14 +07:00
parent 0aef3ff028
commit 329ae8e956
31 changed files with 2766 additions and 155 deletions

View file

@ -18,6 +18,7 @@ import { and, asc, eq, inArray } from "drizzle-orm";
import { db } from "@/db";
import { PdfPathError, readPublicPdf } from "@/lib/server-pdf";
import { fetchSourceBytes, isRemoteSource, RemoteFileError } from "@/lib/remote-file";
import {
annotationReplies,
annotations,
@ -219,14 +220,24 @@ export async function GET(req: Request) {
if (!file) return new Response("ไม่พบไฟล์นี้", { status: 404 });
// Guard path traversal: pdfUrl จาก DB ต้อง resolve แล้วอยู่ใน public/ เท่านั้น (§5)
// N8: pdf_url เป็นรีโมต (ลิงก์ e-Court) → ดึงสดจาก allowlist แทนการอ่านดิสก์
let srcBytes: Buffer;
try {
srcBytes = readPublicPdf(file.pdfUrl);
} catch (err) {
if (err instanceof PdfPathError) {
return new Response("เส้นทางไฟล์ไม่ถูกต้อง", { status: 403 });
if (isRemoteSource(file.pdfUrl)) {
try {
srcBytes = await fetchSourceBytes(file.pdfUrl);
} catch (err) {
if (err instanceof RemoteFileError) return new Response(err.message, { status: 502 });
throw err;
}
} else {
try {
srcBytes = readPublicPdf(file.pdfUrl);
} catch (err) {
if (err instanceof PdfPathError) {
return new Response("เส้นทางไฟล์ไม่ถูกต้อง", { status: 403 });
}
return new Response("อ่านไฟล์ PDF ต้นฉบับไม่ได้", { status: 404 });
}
return new Response("อ่านไฟล์ PDF ต้นฉบับไม่ได้", { status: 404 });
}
// N3: ไฟล์รูปภาพ — สร้าง PDF ใหม่ที่ฝังรูปเต็มหน้า (embedJpg/embedPng + EXIF rotate)

View file

@ -3,6 +3,7 @@ import { eq } from "drizzle-orm";
import { db } from "@/db";
import { files } from "@/db/schema";
import { fixPdfActualText } from "@/lib/pdf-actual-text";
import { fetchSourceBytes, isRemoteSource, RemoteFileError } from "@/lib/remote-file";
import { PdfPathError, readPublicPdf } from "@/lib/server-pdf";
import { fileKindFromUrl, imageContentTypeFromUrl } from "@/utils/file-kind";
@ -25,12 +26,22 @@ export async function GET(req: Request) {
if (!file) return new Response("ไม่พบไฟล์นี้", { status: 404 });
// Guard path traversal: pdfUrl จาก DB ต้อง resolve แล้วอยู่ใน public/ เท่านั้น (§5)
// N8: pdf_url เป็นรีโมต (ลิงก์ e-Court) → ดึงสดจาก allowlist แทนการอ่านดิสก์
let srcBytes: Buffer;
try {
srcBytes = readPublicPdf(file.pdfUrl);
} catch (err) {
if (err instanceof PdfPathError) return new Response(err.message, { status: 400 });
throw err;
if (isRemoteSource(file.pdfUrl)) {
try {
srcBytes = await fetchSourceBytes(file.pdfUrl);
} catch (err) {
if (err instanceof RemoteFileError) return new Response(err.message, { status: 502 });
throw err;
}
} else {
try {
srcBytes = readPublicPdf(file.pdfUrl);
} catch (err) {
if (err instanceof PdfPathError) return new Response(err.message, { status: 400 });
throw err;
}
}
// N3: ไฟล์รูปภาพไม่มี ToUnicode ให้ซ่อม — คืน bytes ดิบ + content-type ถูกต้อง