feat: multi-image paste — collect all images + text from one clipboard event

This commit is contained in:
aedes
2026-04-21 19:41:53 +03:00
parent 8dfa51d92e
commit d3cdeed8d6
2 changed files with 43 additions and 24 deletions

View File

@@ -73,17 +73,18 @@ async function callClaude(modelId, content, accessToken) {
});
}
app.post('/api/chat', express.json({ limit: '25mb' }), async (req, res) => {
const { text, model = 'sonnet', image } = req.body;
app.post('/api/chat', express.json({ limit: '50mb' }), async (req, res) => {
const { text, model = 'sonnet', image, images } = req.body;
const hasText = text?.trim();
if (!hasText && !image) return res.status(400).json({ error: 'text or image required' });
const imgList = Array.isArray(images) ? images : (image ? [image] : []);
if (!hasText && imgList.length === 0) return res.status(400).json({ error: 'text or image required' });
let content;
if (image?.data && image?.media_type) {
content = [
{ type: 'image', source: { type: 'base64', media_type: image.media_type, data: image.data } },
{ type: 'text', text: hasText || 'Analyze the image and answer any questions shown in it.' },
];
if (imgList.length > 0) {
content = imgList
.filter(img => img?.data && img?.media_type)
.map(img => ({ type: 'image', source: { type: 'base64', media_type: img.media_type, data: img.data } }));
content.push({ type: 'text', text: hasText || 'Analyze all images and answer any questions shown in them.' });
} else {
content = text;
}