korean-law-mcp 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { parseHwpxDocument } from "./hwpx-parser.js";
|
|
11
11
|
import { parseHwp5Document } from "./hwp5-parser.js";
|
|
12
|
-
import { parsePdfDocument } from "./pdf-parser.js";
|
|
13
12
|
// ─── 매직바이트 감지 ─────────────────────────────────
|
|
14
13
|
function isHwpxFile(buffer) {
|
|
15
14
|
const bytes = new Uint8Array(buffer.slice(0, 4));
|
|
@@ -59,6 +58,7 @@ async function parseHwp(buffer) {
|
|
|
59
58
|
// ─── PDF 파서 (pdf-parser.ts 위임) ──────────────────
|
|
60
59
|
async function parsePdf(buffer) {
|
|
61
60
|
try {
|
|
61
|
+
const { parsePdfDocument } = await import("./pdf-parser.js");
|
|
62
62
|
const result = await parsePdfDocument(buffer);
|
|
63
63
|
if (result.isImageBased) {
|
|
64
64
|
return {
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 법제처 별표 PDF에서 텍스트를 추출하여 마크다운으로 변환.
|
|
5
5
|
* 이미지 기반 PDF(스캔 문서)는 텍스트 추출이 불가하므로 감지 후 안내.
|
|
6
|
+
*
|
|
7
|
+
* pdfjs-dist는 DOMMatrix 등 브라우저 API를 요구하므로,
|
|
8
|
+
* Vercel 서버리스 등 제한된 환경에서의 모듈 로드 실패를 방지하기 위해
|
|
9
|
+
* lazy import로 실제 파싱 시점에만 로드한다.
|
|
6
10
|
*/
|
|
7
11
|
interface PdfParseResult {
|
|
8
12
|
success: boolean;
|
package/build/lib/pdf-parser.js
CHANGED
|
@@ -3,18 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 법제처 별표 PDF에서 텍스트를 추출하여 마크다운으로 변환.
|
|
5
5
|
* 이미지 기반 PDF(스캔 문서)는 텍스트 추출이 불가하므로 감지 후 안내.
|
|
6
|
+
*
|
|
7
|
+
* pdfjs-dist는 DOMMatrix 등 브라우저 API를 요구하므로,
|
|
8
|
+
* Vercel 서버리스 등 제한된 환경에서의 모듈 로드 실패를 방지하기 위해
|
|
9
|
+
* lazy import로 실제 파싱 시점에만 로드한다.
|
|
6
10
|
*/
|
|
7
|
-
import { getDocument, GlobalWorkerOptions } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
8
11
|
import { createRequire } from "module";
|
|
9
12
|
import { pathToFileURL } from "url";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
let pdfjsLoaded = false;
|
|
14
|
+
async function loadPdfjs() {
|
|
15
|
+
if (pdfjsLoaded)
|
|
16
|
+
return;
|
|
17
|
+
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
18
|
+
const req = createRequire(import.meta.url);
|
|
19
|
+
pdfjs.GlobalWorkerOptions.workerSrc = pathToFileURL(req.resolve("pdfjs-dist/legacy/build/pdf.worker.mjs")).href;
|
|
20
|
+
pdfjsLoaded = true;
|
|
21
|
+
}
|
|
13
22
|
/**
|
|
14
23
|
* PDF ArrayBuffer에서 텍스트 추출 → 마크다운 변환
|
|
15
24
|
*/
|
|
16
25
|
export async function parsePdfDocument(buffer) {
|
|
17
26
|
try {
|
|
27
|
+
await loadPdfjs();
|
|
28
|
+
const { getDocument } = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
18
29
|
const data = new Uint8Array(buffer);
|
|
19
30
|
const doc = await getDocument({
|
|
20
31
|
data,
|