fix: Add API proxy for MinIO assets to work without assets.daarion.space DNS
- Add /api/assets/[...path] proxy route in Next.js
- Add /assets/proxy/{path} endpoint in city-service
- Update normalizeAssetUrl to convert assets.daarion.space URLs to /api/assets/...
- This allows assets to work even if DNS for assets.daarion.space is not configured
This commit is contained in:
@@ -324,6 +324,51 @@ async def update_agent_visibility_endpoint(
|
||||
# Assets & Branding API (Task 042)
|
||||
# =============================================================================
|
||||
|
||||
@router.get("/assets/proxy/{path:path}")
|
||||
async def proxy_asset(path: str):
|
||||
"""
|
||||
Proxy endpoint for serving MinIO assets.
|
||||
Allows serving assets through /api/assets/... instead of requiring assets.daarion.space DNS.
|
||||
"""
|
||||
from lib.assets_client import get_minio_client, ASSETS_BUCKET
|
||||
from fastapi.responses import StreamingResponse
|
||||
import io
|
||||
|
||||
try:
|
||||
client = get_minio_client()
|
||||
|
||||
# Get object from MinIO
|
||||
response = client.get_object(ASSETS_BUCKET, path)
|
||||
|
||||
# Read data
|
||||
data = response.read()
|
||||
response.close()
|
||||
response.release_conn()
|
||||
|
||||
# Determine content type
|
||||
content_type = "application/octet-stream"
|
||||
if path.endswith('.png'):
|
||||
content_type = 'image/png'
|
||||
elif path.endswith('.jpg') or path.endswith('.jpeg'):
|
||||
content_type = 'image/jpeg'
|
||||
elif path.endswith('.webp'):
|
||||
content_type = 'image/webp'
|
||||
elif path.endswith('.gif'):
|
||||
content_type = 'image/gif'
|
||||
|
||||
return StreamingResponse(
|
||||
io.BytesIO(data),
|
||||
media_type=content_type,
|
||||
headers={
|
||||
'Cache-Control': 'public, max-age=86400, immutable',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to proxy asset {path}: {e}")
|
||||
raise HTTPException(status_code=404, detail="Asset not found")
|
||||
|
||||
|
||||
@router.post("/assets/upload")
|
||||
async def upload_asset(
|
||||
file: UploadFile = File(...),
|
||||
|
||||
Reference in New Issue
Block a user