Fix asset_type detection when recording runs from L1
Fetch media_type and ipfs_cid from L1's cache endpoint instead of hardcoding asset_type to "video". This fixes images being incorrectly displayed as videos. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
19
server.py
19
server.py
@@ -1731,6 +1731,22 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
|
||||
if not output_hash:
|
||||
raise HTTPException(400, "Run has no output hash")
|
||||
|
||||
# Fetch media type from L1 cache
|
||||
try:
|
||||
cache_resp = requests.get(
|
||||
f"{l1_url}/cache/{output_hash}",
|
||||
headers={"Accept": "application/json"},
|
||||
timeout=10
|
||||
)
|
||||
cache_resp.raise_for_status()
|
||||
cache_info = cache_resp.json()
|
||||
media_type = cache_info.get("media_type", "image")
|
||||
ipfs_cid = cache_info.get("ipfs_cid")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch cache info from L1: {e}")
|
||||
media_type = "image" # Default fallback
|
||||
ipfs_cid = None
|
||||
|
||||
# Build provenance from run
|
||||
provenance = {
|
||||
"inputs": [{"content_hash": h} for h in run.get("inputs", [])],
|
||||
@@ -1747,7 +1763,8 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
|
||||
return await _register_asset_impl(RegisterRequest(
|
||||
name=req.output_name,
|
||||
content_hash=output_hash,
|
||||
asset_type="video", # Could be smarter about this
|
||||
ipfs_cid=ipfs_cid,
|
||||
asset_type=media_type, # Detected from L1 cache
|
||||
tags=["rendered", "l1"],
|
||||
metadata={"l1_server": l1_url, "l1_run_id": req.run_id},
|
||||
provenance=provenance
|
||||
|
||||
Reference in New Issue
Block a user