fix: whitelist parser metadata to its documented fields before storing

The unfiltered metadata spread let a custom parser overwrite managed
columns — stashing 'file_path' in metadata silently repointed the stored
row at the user's original file, which delete_document would then
unlink. ParsedDocument documents page_count/line_count as the only
persisted metadata; merge exactly those.
This commit is contained in:
Ray 2026-07-21 17:58:03 +08:00
parent a11493502f
commit ad7f152ea7

View file

@ -128,13 +128,16 @@ class LocalBackend:
**({"images": n.images} if n.images else {})}
for n in parsed.nodes if n.content]
meta = parsed.metadata or {}
self._storage.save_document(collection, doc_id, {
"doc_name": parsed.doc_name,
"doc_description": result.get("doc_description", ""),
"file_path": str(managed_path),
"file_hash": file_hash,
"doc_type": ext.lstrip("."),
**(parsed.metadata or {}), # parser-reported, e.g. page_count / line_count
# Only the documented parser metadata fields — anything else a
# parser reports must not reach (or overwrite) storage columns.
**{k: meta[k] for k in ("page_count", "line_count") if k in meta},
"structure": result["structure"],
"pages": pages,
})