feat: multi-image paste — collect all images + text from one clipboard event
This commit is contained in:
17
server.js
17
server.js
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user