chore: snapshot workflow migration progress
This commit is contained in:
@@ -13,6 +13,9 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.database import get_db
|
||||
from app.core.render_paths import resolve_result_path
|
||||
from app.config import settings
|
||||
from app.domains.media.models import MediaAsset, MediaAssetType
|
||||
from app.models.cad_file import CadFile, ProcessingStatus
|
||||
from app.models.order import Order
|
||||
from app.models.order_item import OrderItem
|
||||
@@ -191,6 +194,38 @@ async def _get_cad_file(cad_id: uuid.UUID, db: AsyncSession) -> CadFile:
|
||||
return cad
|
||||
|
||||
|
||||
async def _resolve_gltf_path(cad: CadFile, db: AsyncSession) -> Path | None:
|
||||
"""Resolve the best available GLTF/GLB path for a CAD file.
|
||||
|
||||
Prefer the legacy cad_files.gltf_path for compatibility, but fall back to
|
||||
the canonical media_assets.gltf_geometry record written by the newer export
|
||||
pipeline.
|
||||
"""
|
||||
if cad.gltf_path:
|
||||
legacy_path = resolve_result_path(cad.gltf_path) or Path(cad.gltf_path)
|
||||
if legacy_path.exists():
|
||||
return legacy_path
|
||||
|
||||
asset_result = await db.execute(
|
||||
select(MediaAsset)
|
||||
.where(
|
||||
MediaAsset.cad_file_id == cad.id,
|
||||
MediaAsset.asset_type == MediaAssetType.gltf_geometry,
|
||||
MediaAsset.is_archived == False, # noqa: E712
|
||||
)
|
||||
.order_by(MediaAsset.created_at.desc())
|
||||
)
|
||||
asset = asset_result.scalars().first()
|
||||
if asset and asset.storage_key:
|
||||
asset_path = resolve_result_path(asset.storage_key)
|
||||
if asset_path is None:
|
||||
asset_path = Path(settings.upload_dir) / asset.storage_key.lstrip("/")
|
||||
if asset_path.exists():
|
||||
return asset_path
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@router.get("/{id}/thumbnail")
|
||||
async def get_thumbnail(
|
||||
id: uuid.UUID,
|
||||
@@ -228,20 +263,13 @@ async def get_model(
|
||||
):
|
||||
"""Serve the glTF file for a CAD file."""
|
||||
cad = await _get_cad_file(id, db)
|
||||
|
||||
if not cad.gltf_path:
|
||||
gltf_path = await _resolve_gltf_path(cad, db)
|
||||
if gltf_path is None:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="glTF model not yet generated for this CAD file",
|
||||
)
|
||||
|
||||
gltf_path = Path(cad.gltf_path)
|
||||
if not gltf_path.exists():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="glTF file missing from storage",
|
||||
)
|
||||
|
||||
# glTF files may be either .gltf (JSON) or .glb (binary)
|
||||
suffix = gltf_path.suffix.lower()
|
||||
if suffix == ".glb":
|
||||
|
||||
Reference in New Issue
Block a user