fix: add static files proxy and improve upload URL handling

This commit is contained in:
Apple
2025-12-01 02:45:07 -08:00
parent 7843ff3d86
commit 9c79b6e526
3 changed files with 52 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
import { NextRequest, NextResponse } from 'next/server';
const CITY_SERVICE_URL =
process.env.INTERNAL_API_URL ||
process.env.CITY_SERVICE_URL ||
'http://daarion-city-service:7001';
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ path: string[] }> }
) {
const { path } = await params;
const filePath = path.join('/');
try {
const upstream = await fetch(
`${CITY_SERVICE_URL}/static/uploads/${filePath}`,
{ cache: 'no-store' }
);
if (!upstream.ok) {
return new NextResponse('Not found', { status: 404 });
}
const contentType = upstream.headers.get('content-type') || 'application/octet-stream';
const body = await upstream.arrayBuffer();
return new NextResponse(body, {
status: 200,
headers: {
'Content-Type': contentType,
'Cache-Control': 'public, max-age=31536000, immutable',
},
});
} catch (error) {
console.error('[static] Error:', error);
return new NextResponse('Internal error', { status: 500 });
}
}

View File

@@ -44,7 +44,12 @@ export function AgentAvatarUpload({
}
const uploadData = await uploadRes.json();
const imageUrl = uploadData.processed_url || uploadData.original_url;
// Convert relative URL to use our API proxy
let imageUrl = uploadData.processed_url || uploadData.original_url;
if (imageUrl && imageUrl.startsWith('/static/')) {
// Proxy through our API route
imageUrl = `/api${imageUrl}`;
}
// Update agent DAIS
const updateRes = await fetch(`/api/agents/${agentId}/dais`, {

View File

@@ -47,7 +47,12 @@ export function MicrodaoBrandingCard({
}
const uploadData = await uploadRes.json();
const imageUrl = uploadData.processed_url || uploadData.original_url;
// Convert relative URL to use our API proxy
let imageUrl = uploadData.processed_url || uploadData.original_url;
if (imageUrl && imageUrl.startsWith('/static/')) {
// Proxy through our API route
imageUrl = `/api${imageUrl}`;
}
// Update branding
const brandingRes = await fetch(`/api/microdao/${slug}/branding`, {