feat(F-G-H-I): STL cache, invoices, import validation, notification settings
Phase F — STL Hash Cache:
- Migration 041: step_file_hash column on cad_files
- cache_service.py: SHA256 hash + MinIO-backed STL cache (check/store)
- render_step_thumbnail: compute+persist hash before render
- generate_stl_cache: check MinIO cache before cadquery conversion, store after
Phase G — Invoices:
- Migration 042: invoices + invoice_lines tables with RLS
- Invoice/InvoiceLine models + schemas
- billing service: generate_invoice_number (INV-YYYY-NNNN), create/list/get/delete/PDF
- WeasyPrint PDF generation; backend Dockerfile + pyproject.toml deps
- invoice_router with 6 endpoints; registered in main.py
- frontend: Billing.tsx page + api/billing.ts; route + nav link
Phase H — Import Sanity Check:
- Migration 043: import_validations table
- ImportValidation model + schemas
- run_sanity_check: material fuzzy-match (cutoff=0.8), STEP availability, duplicate detection
- validate_excel_import Celery task (queue: step_processing)
- uploads.py: create ImportValidation on /excel, fire task, expose GET /validations/{id}
- frontend: Upload.tsx polling ValidationDialog with Ampel status indicators
Phase I — Notification Settings:
- Migration 044: notification_configs table (user×event×channel toggles)
- NotificationConfig model + seeds (in_app=true, email=false)
- get/upsert/reset config endpoints on /notifications/config
- frontend: NotificationSettings.tsx page + api/notifications.ts extensions
Infrastructure:
- docker-compose.yml: add worker-thumbnail service (concurrency=1, Q=thumbnail_rendering)
- Fix Dockerfile: libgdk-pixbuf-2.0-0 (correct Debian bookworm package name)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""SHA256-based STL conversion cache using MinIO."""
|
||||
from __future__ import annotations
|
||||
import hashlib
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CACHE_PREFIX = "conversion-cache"
|
||||
|
||||
|
||||
def compute_step_hash(file_path: str) -> str:
|
||||
"""Compute SHA256 hash of a STEP file."""
|
||||
h = hashlib.sha256()
|
||||
with open(file_path, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(65536), b""):
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def _cache_key(step_hash: str, quality: str) -> str:
|
||||
return f"{CACHE_PREFIX}/{step_hash}_{quality}.stl"
|
||||
|
||||
|
||||
def check_stl_cache(step_hash: str, quality: str) -> bytes | None:
|
||||
"""Return STL bytes from MinIO cache if present, else None."""
|
||||
from app.core.storage import get_storage
|
||||
storage = get_storage()
|
||||
key = _cache_key(step_hash, quality)
|
||||
try:
|
||||
if storage.exists(key):
|
||||
return storage.download_bytes(key)
|
||||
return None
|
||||
except Exception as exc:
|
||||
logger.warning("Cache check failed for %s: %s", key, exc)
|
||||
return None
|
||||
|
||||
|
||||
def store_stl_cache(step_hash: str, quality: str, stl_path: str) -> None:
|
||||
"""Upload local STL file to MinIO cache."""
|
||||
from app.core.storage import get_storage
|
||||
storage = get_storage()
|
||||
key = _cache_key(step_hash, quality)
|
||||
try:
|
||||
storage.upload(stl_path, key)
|
||||
logger.info("Stored STL cache: %s", key)
|
||||
except Exception as exc:
|
||||
logger.warning("Failed to store STL cache %s: %s", key, exc)
|
||||
@@ -31,6 +31,7 @@ class CadFile(Base):
|
||||
error_message: Mapped[str] = mapped_column(String(2000), nullable=True)
|
||||
render_log: Mapped[dict] = mapped_column(JSONB, nullable=True)
|
||||
mesh_attributes: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
|
||||
step_file_hash: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
tenant_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("tenants.id"), nullable=True, index=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user