chore: snapshot workflow migration progress
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from app.config import settings
|
||||
|
||||
|
||||
def asset_library_dir() -> Path:
|
||||
return Path(settings.upload_dir) / "asset-libraries"
|
||||
|
||||
|
||||
def list_asset_library_blends() -> list[Path]:
|
||||
directory = asset_library_dir()
|
||||
if not directory.is_dir():
|
||||
return []
|
||||
|
||||
return sorted(
|
||||
(path for path in directory.glob("*.blend") if path.is_file()),
|
||||
key=lambda path: (path.stat().st_mtime, path.name),
|
||||
reverse=True,
|
||||
)
|
||||
|
||||
|
||||
def resolve_asset_library_blend_path(
|
||||
*,
|
||||
blend_file_path: str | None = None,
|
||||
asset_library_id: Any | None = None,
|
||||
) -> str | None:
|
||||
"""Resolve the best available .blend path for an asset library.
|
||||
|
||||
Resolution order:
|
||||
1. explicit configured path, when it exists
|
||||
2. canonical uploads/asset-libraries/<id>.blend path
|
||||
3. newest available .blend under uploads/asset-libraries
|
||||
"""
|
||||
if blend_file_path:
|
||||
configured = Path(blend_file_path)
|
||||
if configured.is_file():
|
||||
return str(configured)
|
||||
|
||||
if asset_library_id:
|
||||
candidate = asset_library_dir() / f"{asset_library_id}.blend"
|
||||
if candidate.is_file():
|
||||
return str(candidate)
|
||||
|
||||
available = list_asset_library_blends()
|
||||
if available:
|
||||
return str(available[0])
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user