diff --git a/server.py b/server.py index de3bbe1..256a15f 100644 --- a/server.py +++ b/server.py @@ -161,8 +161,21 @@ def cache_file(source: Path, node_type: str = "output") -> str: Copy file to cache using L1CacheManager, return content hash. Uses artdag's Cache internally for proper tracking. + Also creates a symlink in legacy location for backward compatibility. """ cached = cache_manager.put(source, node_type=node_type) + + # Create symlink in legacy location for backward compatibility + legacy_path = CACHE_DIR / cached.content_hash + if not legacy_path.exists(): + try: + legacy_path.symlink_to(cached.path) + except (OSError, FileExistsError): + # Symlink failed, try copy + import shutil + if not legacy_path.exists(): + shutil.copy2(cached.path, legacy_path) + return cached.content_hash @@ -754,9 +767,16 @@ async def list_runs(request: Request, page: int = 1, limit: int = 20): @app.get("/cache/{content_hash}") async def get_cached(content_hash: str): """Get cached content by hash.""" - cache_path = CACHE_DIR / content_hash + # Try cache_manager first (new location) + cache_path = cache_manager.get_by_content_hash(content_hash) - if not cache_path.exists(): + # Fallback to legacy location + if not cache_path: + legacy_path = CACHE_DIR / content_hash + if legacy_path.exists(): + cache_path = legacy_path + + if not cache_path or not cache_path.exists(): raise HTTPException(404, f"Content {content_hash} not in cache") return FileResponse(cache_path) @@ -765,10 +785,18 @@ async def get_cached(content_hash: str): @app.get("/cache/{content_hash}/mp4") async def get_cached_mp4(content_hash: str): """Get cached content as MP4 (transcodes MKV on first request, caches result).""" - cache_path = CACHE_DIR / content_hash + # Try cache_manager first (new location) + cache_path = cache_manager.get_by_content_hash(content_hash) + + # Fallback to legacy location + if not cache_path: + legacy_path = CACHE_DIR / content_hash + if legacy_path.exists(): + cache_path = legacy_path + mp4_path = CACHE_DIR / f"{content_hash}.mp4" - if not cache_path.exists(): + if not cache_path or not cache_path.exists(): raise HTTPException(404, f"Content {content_hash} not in cache") # If MP4 already cached, serve it