fix: add static files proxy and improve upload URL handling
This commit is contained in:
40
apps/web/src/app/api/static/uploads/[...path]/route.ts
Normal file
40
apps/web/src/app/api/static/uploads/[...path]/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`, {
|
||||
|
||||
@@ -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`, {
|
||||
|
||||
Reference in New Issue
Block a user