Add configurable IPFS gateway URL with local gateway as primary

- IPFS_GATEWAY_URL env var for local gateway (e.g., https://ipfs.celery-artdag.rose-ash.com)
- Local gateway shown first with green button when configured
- Removed Pinata from public gateways list

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-08 18:09:51 +00:00
parent e25b61e6ab
commit c0c3096e48
2 changed files with 30 additions and 18 deletions

View File

@@ -40,6 +40,9 @@ L1_PUBLIC_URL = os.environ.get("L1_PUBLIC_URL", "http://localhost:8100")
# Default L2 for login redirect when not logged in (user can login to any L2)
DEFAULT_L2_SERVER = os.environ.get("DEFAULT_L2_SERVER", "http://localhost:8200")
# IPFS gateway URL for public access to IPFS content
IPFS_GATEWAY_URL = os.environ.get("IPFS_GATEWAY_URL", "")
# Cache directory (use /data/cache in Docker, ~/.artdag/cache locally)
CACHE_DIR = Path(os.environ.get("CACHE_DIR", str(Path.home() / ".artdag" / "cache")))
CACHE_DIR.mkdir(parents=True, exist_ok=True)
@@ -1778,6 +1781,30 @@ async def cache_detail(content_hash: str, request: Request):
# Add IPFS section if we have a CID
if ipfs_cid:
# Build gateway links - local gateway first if configured
gateway_links = []
if IPFS_GATEWAY_URL:
gateway_links.append(f'''
<a href="{IPFS_GATEWAY_URL}/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-green-600 hover:bg-green-700 text-white text-sm rounded-lg transition-colors">
Local Gateway
</a>''')
gateway_links.extend([
f'''<a href="https://ipfs.io/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
ipfs.io
</a>''',
f'''<a href="https://dweb.link/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
dweb.link
</a>''',
f'''<a href="https://cloudflare-ipfs.com/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
Cloudflare
</a>''',
])
gateways_html = '\n'.join(gateway_links)
content += f'''
<div class="border-t border-dark-500 pt-6 mt-6">
<h2 class="text-lg font-semibold text-white mb-4">IPFS</h2>
@@ -1785,24 +1812,9 @@ async def cache_detail(content_hash: str, request: Request):
<div class="text-sm text-gray-400 mb-1">Content Identifier (CID)</div>
<div class="font-mono text-xs text-gray-200 break-all">{ipfs_cid}</div>
</div>
<div class="text-sm text-gray-400 mb-2">Public Gateways:</div>
<div class="text-sm text-gray-400 mb-2">Gateways:</div>
<div class="flex flex-wrap gap-2">
<a href="https://ipfs.io/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
ipfs.io
</a>
<a href="https://dweb.link/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
dweb.link
</a>
<a href="https://cloudflare-ipfs.com/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
Cloudflare
</a>
<a href="https://gateway.pinata.cloud/ipfs/{ipfs_cid}" target="_blank" rel="noopener"
class="px-3 py-1 bg-purple-600 hover:bg-purple-700 text-white text-sm rounded-lg transition-colors">
Pinata
</a>
{gateways_html}
</div>
</div>
'''