feat: content_hash + дедупликация при загрузке
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user