chore: snapshot workflow migration progress
This commit is contained in:
@@ -16,6 +16,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload, joinedload
|
||||
|
||||
from app.config import settings
|
||||
from app.core.render_paths import (
|
||||
resolve_result_path,
|
||||
resolve_public_asset_url,
|
||||
result_path_to_public_url,
|
||||
)
|
||||
from app.database import get_db
|
||||
from app.models.cad_file import CadFile, ProcessingStatus
|
||||
from app.models.material import Material
|
||||
@@ -829,24 +834,12 @@ VIDEO_EXTENSIONS = {".mp4", ".webm", ".avi", ".mov"}
|
||||
|
||||
def _result_path_to_url(result_path: str) -> str | None:
|
||||
"""Convert an internal result_path to a servable static URL."""
|
||||
# Flamenco / shared renders: /shared/renders/X/file.jpg → /renders/X/file.jpg
|
||||
if "/renders/" in result_path:
|
||||
idx = result_path.index("/renders/")
|
||||
return result_path[idx:]
|
||||
# Celery renders stored as thumbnails: /app/uploads/thumbnails/X.png → /thumbnails/X.png
|
||||
if "/thumbnails/" in result_path:
|
||||
idx = result_path.index("/thumbnails/")
|
||||
return result_path[idx:]
|
||||
return None
|
||||
return result_path_to_public_url(result_path, require_exists=False)
|
||||
|
||||
|
||||
def _resolve_disk_path(url: str) -> Path | None:
|
||||
"""Given a servable URL like /renders/X/file.jpg, resolve to disk path."""
|
||||
if url.startswith("/renders/"):
|
||||
return Path(settings.upload_dir) / "renders" / url[len("/renders/"):]
|
||||
if url.startswith("/thumbnails/"):
|
||||
return Path(settings.upload_dir) / "thumbnails" / url[len("/thumbnails/"):]
|
||||
return None
|
||||
return resolve_public_asset_url(url)
|
||||
|
||||
|
||||
@router.get("/{product_id}/renders")
|
||||
@@ -983,9 +976,8 @@ async def download_product_renders(
|
||||
raise HTTPException(404, detail="No completed renders found for the selected lines")
|
||||
|
||||
def _resolve_path(p: str) -> str:
|
||||
if p.startswith("/shared/"):
|
||||
return settings.upload_dir + p[len("/shared"):]
|
||||
return p
|
||||
resolved = resolve_result_path(p)
|
||||
return str(resolved) if resolved is not None else p
|
||||
|
||||
def _safe(s: str) -> str:
|
||||
return re.sub(r"[^\w\-.]", "_", s).strip("_")
|
||||
@@ -1147,4 +1139,3 @@ async def delete_render_position(
|
||||
raise HTTPException(404, detail="Render position not found")
|
||||
await db.delete(pos)
|
||||
await db.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user