修回写两bug:insert_pdf跨版本失效改直存源文档;app页码0/1基错位。线上e2e全绿
This commit is contained in:
parent
8b6b886bd1
commit
2323fa6150
@ -16,3 +16,8 @@
|
|||||||
- PaddleOCR 接入(扫描件路径)
|
- PaddleOCR 接入(扫描件路径)
|
||||||
- 跨词/跨行 PII 识别优化(平台组已发现紧贴文字漏检问题)
|
- 跨词/跨行 PII 识别优化(平台组已发现紧贴文字漏检问题)
|
||||||
- 人审界面 + 审计日志
|
- 人审界面 + 审计日志
|
||||||
|
|
||||||
|
## 首轮线上端到端验收(11:03 更新)
|
||||||
|
- 测试件:含身份证/手机号/邮箱的中文合同 PDF,经 https://tm.tongueclaw.com/ 全流程
|
||||||
|
- 结果:三类敏感信息全部从文本层彻底删除 ✅ 非敏感正文完整保留 ✅ 脱敏件下载正常 ✅
|
||||||
|
- 修复记录:① redactor insert_pdf 跨版本失效 → 改直接保存源文档;② app 页码 1 基/0 基错位导致回写落空 → 已修;③ 服务器 PyMuPDF 统一锁 1.26.5;④ 服务器加 1G swap 防 OOM
|
||||||
|
|||||||
7
app.py
7
app.py
@ -51,15 +51,16 @@ def process_pdf(input_path: Path, out_path: Path, task: dict):
|
|||||||
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
||||||
hits, items = [], []
|
hits, items = [], []
|
||||||
for i, page in enumerate(doc):
|
for i, page in enumerate(doc):
|
||||||
page_no = i + 1
|
page_no = i + 1 # 对外展示用 1 基页码
|
||||||
words = tmkit.extract_page_words(page)
|
words = tmkit.extract_page_words(page)
|
||||||
found = detector.scan_page_words(words, page_no)
|
found = detector.scan_page_words(words, i) # tmkit/redactor 内部用 0 基
|
||||||
for h in found or []:
|
for h in found or []:
|
||||||
items.append({"type": h.get("type", "未知"),
|
items.append({"type": h.get("type", "未知"),
|
||||||
"text": h.get("text", ""),
|
"text": h.get("text", ""),
|
||||||
"page": h.get("page", page_no)})
|
"page": h.get("page", page_no)})
|
||||||
if h.get("bbox") is not None:
|
if h.get("bbox") is not None:
|
||||||
hits.append({"page": h.get("page", page_no), "bbox": h["bbox"]})
|
# 回写用 0 基页码,展示用 1 基,两者分开
|
||||||
|
hits.append({"page": i, "bbox": h["bbox"]})
|
||||||
|
|
||||||
# 阶段 4:脱敏回写
|
# 阶段 4:脱敏回写
|
||||||
task["stage"] = "脱敏回写"
|
task["stage"] = "脱敏回写"
|
||||||
|
|||||||
@ -26,7 +26,6 @@ def redact_pdf(pdf_bytes: bytes, hits: List[dict], method: str = "redact") -> by
|
|||||||
by_page.setdefault(h["page"], []).append(h["bbox"])
|
by_page.setdefault(h["page"], []).append(h["bbox"])
|
||||||
|
|
||||||
src = fitz.open(stream=pdf_bytes, filetype="pdf")
|
src = fitz.open(stream=pdf_bytes, filetype="pdf")
|
||||||
out = fitz.open()
|
|
||||||
for pno, page in enumerate(src):
|
for pno, page in enumerate(src):
|
||||||
boxes = by_page.get(pno, [])
|
boxes = by_page.get(pno, [])
|
||||||
if method == "redact":
|
if method == "redact":
|
||||||
@ -39,10 +38,9 @@ def redact_pdf(pdf_bytes: bytes, hits: List[dict], method: str = "redact") -> by
|
|||||||
page.draw_rect(bbox, color=None, fill=(0, 0, 0))
|
page.draw_rect(bbox, color=None, fill=(0, 0, 0))
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"unknown method: {method}")
|
raise ValueError(f"unknown method: {method}")
|
||||||
out.insert_pdf(src, from_page=pno, to_page=pno)
|
# 直接保存原文档本身(apply_redactions 已就地修改页对象)。
|
||||||
# 注意:redact 修改的是 src 中的页,insert_pdf 会拷贝修改后的页
|
# 不用 insert_pdf 搬运到新文档——部分 PyMuPDF 版本会拷贝未脱敏的原始页。
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
out.save(buf)
|
src.save(buf, garbage=3, deflate=True)
|
||||||
src.close()
|
src.close()
|
||||||
out.close()
|
|
||||||
return buf.getvalue()
|
return buf.getvalue()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user