From 3bac27265b66b6bf0cfeb2c3fe04d2c6630ab293 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 1 Feb 2026 12:47:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E9=80=BB=E8=BE=91=E9=81=BF=E5=85=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 只提取原始图片 URL,不提取缩略图 2. 有 markdown 格式时不再匹配普通 URL Co-authored-by: Cursor --- components/canvas/CanvasChatPanel.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index b2a9b76..1d75462 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -33,24 +33,31 @@ interface CanvasChatPanelProps { // 建议卡片数据 - 已移除 const SUGGESTIONS: { title: string; desc: string; image: string }[] = []; -// 从消息中提取图片 URL +// 从消息中提取图片 URL(只提取原始图片,避免重复) function extractImageUrls(text: string): string[] { const urls: string[] = []; - // 匹配 markdown 图片格式: ![alt|||originalUrl|||size](thumbnailUrl) - const markdownRegex = /!\[(?:thumb)?\|\|\|([^|]+)\|\|\|[^\]]*\]\([^)]+\)/g; + // 匹配 markdown 图片格式: ![thumb|||originalUrl|||size](thumbnailUrl) + // 只提取原始图片 URL(第一个 ||| 和第二个 ||| 之间的 URL) + const markdownRegex = /!\[(?:thumb)?\|\|\|([^|]+)\|\|\|[^\]]*\]\(([^)]+)\)/g; let match; + let hasMarkdownImages = false; + while ((match = markdownRegex.exec(text)) !== null) { if (match[1]) { - urls.push(match[1]); + urls.push(match[1]); // 原始图片 URL + hasMarkdownImages = true; } } - // 匹配普通图片 URL - const urlRegex = /https?:\/\/[^\s"'<>]+\.(?:jpg|jpeg|png|gif|webp)/gi; - const urlMatches = text.match(urlRegex); - if (urlMatches) { - urls.push(...urlMatches.filter(url => !urls.includes(url))); + // 只有在没有 markdown 格式图片时,才匹配普通图片 URL + // 这样可以避免重复匹配缩略图 URL + if (!hasMarkdownImages) { + const urlRegex = /https?:\/\/[^\s"'<>]+\.(?:jpg|jpeg|png|gif|webp)/gi; + const urlMatches = text.match(urlRegex); + if (urlMatches) { + urls.push(...urlMatches.filter(url => !urls.includes(url))); + } } return urls;