feat: content_hash + дедупликация при загрузке

This commit is contained in:
2026-06-28 10:03:52 +04:00
parent fad55182b9
commit 8eae0eec64
3 changed files with 25 additions and 5 deletions
+11 -1
View File
@@ -77,6 +77,15 @@ def store_document(filename: str, file_data: bytes, contract_id: str = "",
if not filename or not file_data:
return {"ok": False, "error": "no file"}
import hashlib
content_hash = hashlib.sha256(file_data).hexdigest()
# Dedup: same content in same batch → skip
if batch_id:
existing = documents.get_by_hash(batch_id, content_hash)
if existing:
return {"ok": True, "duplicate_of": existing["id"], "filename": filename}
mime = _mime_for(filename)
b64 = base64.b64encode(file_data).decode()
@@ -86,7 +95,8 @@ def store_document(filename: str, file_data: bytes, contract_id: str = "",
except Exception:
pass
doc = documents.insert(filename, mime, b64, batch_id=batch_id, zip_source=zip_source)
doc = documents.insert(filename, mime, b64, batch_id=batch_id, zip_source=zip_source,
content_hash=content_hash)
if not contract_id:
from datetime import datetime