Add ipfs_cid support to asset update endpoint
Allow updating asset's IPFS CID via PATCH endpoint. Pins content on IPFS when CID is provided. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
10
server.py
10
server.py
@@ -143,6 +143,7 @@ class UpdateAssetRequest(BaseModel):
|
||||
tags: Optional[list[str]] = None
|
||||
metadata: Optional[dict] = None
|
||||
origin: Optional[dict] = None
|
||||
ipfs_cid: Optional[str] = None # IPFS content identifier
|
||||
|
||||
|
||||
# ============ Storage (Database) ============
|
||||
@@ -1596,6 +1597,15 @@ async def update_asset(name: str, req: UpdateAssetRequest, user: User = Depends(
|
||||
updates["metadata"] = {**asset.get("metadata", {}), **req.metadata}
|
||||
if req.origin is not None:
|
||||
updates["origin"] = req.origin
|
||||
if req.ipfs_cid is not None:
|
||||
updates["ipfs_cid"] = req.ipfs_cid
|
||||
# Pin on IPFS
|
||||
try:
|
||||
import ipfs_client
|
||||
if ipfs_client.is_available():
|
||||
ipfs_client.pin(req.ipfs_cid)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to pin IPFS content {req.ipfs_cid}: {e}")
|
||||
|
||||
# Update asset in database
|
||||
updated_asset = await db.update_asset(name, updates)
|
||||
|
||||
Reference in New Issue
Block a user