feat(storage): X14 Phase 2c — route remaining sync write-sites through storage.py
Completes the write-side rewiring (INV-STG1) for the call-sites that run in synchronous contexts, via a new blocking facade in storage.py (put_bytes_sync / put_file_sync — asyncio.run, or a worker thread when a loop is already running): - services/extractor.py: multimodal thumbnail JPEGs → DERIVED (rendered in a to_thread worker) - services/docx_reviser.py: track-changes save (_save_docx_xml) + empty-diff copy (copy_with_revisions) → DOCUMENTS - services/docx_retrofit.py: in-place retrofit backup → DOCUMENTS Each site keeps a fallback to a direct disk write when the target path is outside DATA_DIR (caller-provided). Under the default STORAGE_BACKEND= filesystem the bytes land exactly where they did before — zero behaviour change. Also: mcp_env_catalog MINIO_ENDPOINT default updated to the durable container-name endpoint (http://minio-bx2ykvw94xbutsex41hz4vv8:9000), matching the Coolify "Connect to Predefined Network" change made for network durability. All binary write-sites now flow through storage.py. git-tracked text (case.json/notes/research-md/draft-md) stays on disk by design (INV-STG7); court-fetch temp files are ephemeral. tests: +2 (thumbnail renderer routes through storage; put_bytes_sync round-trip); 55 storage/docx/track-changes green; 244 collected, no import breakage. Keeps G2; completes INV-STG1 write coverage. Spec: docs/spec/X14-storage-minio.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@ from docx import Document as DocxDocument
|
||||
from striprtf.striprtf import rtf_to_text
|
||||
|
||||
from legal_mcp import config
|
||||
from legal_mcp.services import storage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from google.cloud import vision
|
||||
@@ -345,7 +346,19 @@ def render_pages_for_multimodal(
|
||||
max(1, int(img.height * ratio)),
|
||||
)
|
||||
thumb = img.resize(thumb_size, Image.Resampling.LANCZOS)
|
||||
thumb.save(thumb_path, "JPEG", quality=75, optimize=True)
|
||||
# Persist the thumbnail (a DERIVED, regenerable artifact)
|
||||
# through the storage layer (INV-STG1). Under the filesystem
|
||||
# backend it lands at thumb_path exactly as before.
|
||||
_tbuf = io.BytesIO()
|
||||
thumb.save(_tbuf, "JPEG", quality=75, optimize=True)
|
||||
try:
|
||||
_tkey = thumb_path.resolve().relative_to(
|
||||
Path(config.DATA_DIR).resolve()).as_posix()
|
||||
storage.put_bytes_sync(
|
||||
_tkey, _tbuf.getvalue(), bucket=storage.Bucket.DERIVED,
|
||||
content_type="image/jpeg")
|
||||
except ValueError:
|
||||
thumb.save(thumb_path, "JPEG", quality=75, optimize=True)
|
||||
|
||||
out.append((img, thumb_path))
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user