fix: serve uploaded images via API route (public/ is read-only in production)
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s

Next.js bakes public/ at build time — dynamically uploaded files were
never served in Docker standalone mode. Store uploads in data/uploads/
and serve via /api/uploads/ with a rewrite for backward compatibility.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-27 22:56:22 +02:00
parent ae89f8a014
commit 0fbb8aa599
8 changed files with 81 additions and 16 deletions

View File

@@ -49,7 +49,7 @@ export async function POST(req: Request) {
// 2. Parse request body — messages arrive as UIMessage[] from DefaultChatTransport
const body = await req.json()
console.log('[Chat] body keys:', Object.keys(body), 'noteContext?', !!body.noteContext, 'images?', body.noteContext?.images?.length)
const { messages: rawMessages, conversationId, notebookId, language, webSearch, noteContext } = body as {
messages: UIMessage[]
conversationId?: string
@@ -331,22 +331,16 @@ Tu as accès à ces outils pour des recherches approfondies :
// Load note images as base64 for vision-capable models
let imageContextParts: Array<{ type: 'image'; image: string }> = []
if (noteContext?.images && noteContext.images.length > 0) {
console.log('[Chat] noteContext.images:', noteContext.images)
for (const imgPath of noteContext.images.slice(0, 4)) {
try {
const fullPath = path.join(process.cwd(), 'public', imgPath)
console.log('[Chat] reading image:', fullPath)
const fullPath = path.join(process.cwd(), 'data', imgPath)
const buffer = await readFile(fullPath)
const ext = path.extname(imgPath).toLowerCase()
const mime = ext === '.png' ? 'image/png' : ext === '.gif' ? 'image/gif' : ext === '.webp' ? 'image/webp' : 'image/jpeg'
const base64 = `data:${mime};base64,${buffer.toString('base64')}`
imageContextParts.push({ type: 'image', image: base64 })
console.log('[Chat] image loaded, size:', buffer.length, 'bytes')
} catch (err) {
console.error('[Chat] failed to read image:', imgPath, err)
}
} catch {}
}
console.log('[Chat] total image parts:', imageContextParts.length)
}
let copilotContext = ''