Add IPFS CID support for asset lookup

- Upload endpoint returns both CID and content_hash
- Cache manager handles both SHA3-256 hashes and IPFS CIDs
- get_by_cid() fetches from IPFS if not cached locally
- Execute tasks support :cid in addition to :hash

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-12 07:36:18 +00:00
parent c7c7c90909
commit 494a2a8650
4 changed files with 51 additions and 14 deletions

View File

@@ -453,8 +453,8 @@ class CacheService:
content: bytes,
filename: str,
actor_id: str,
) -> Tuple[Optional[str], Optional[str]]:
"""Upload content to cache. Returns (content_hash, error)."""
) -> Tuple[Optional[str], Optional[str], Optional[str]]:
"""Upload content to cache. Returns (content_hash, ipfs_cid, error)."""
import tempfile
try:
@@ -466,7 +466,7 @@ class CacheService:
# Detect MIME type before moving file
mime_type = get_mime_type(tmp_path)
# Store in cache
# Store in cache (also stores in IPFS)
cached, ipfs_cid = self.cache.put(tmp_path, node_type="upload", move=True)
content_hash = cached.content_hash
@@ -479,9 +479,9 @@ class CacheService:
filename=filename
)
return content_hash, None
return content_hash, ipfs_cid, None
except Exception as e:
return None, f"Upload failed: {e}"
return None, None, f"Upload failed: {e}"
async def list_media(
self,