|
@@ -945,13 +945,22 @@ const generate = async (message: ChatMessage) => {
|
|
|
console.log('图片', result)
|
|
console.log('图片', result)
|
|
|
const content = await result.promise
|
|
const content = await result.promise
|
|
|
console.log('event.data', content)
|
|
console.log('event.data', content)
|
|
|
- // 从content中提取图片链接:先判断content是否本身就是链接,是则直接使用,否则从markdown格式中提取
|
|
|
|
|
|
|
+ // 从content中提取图片链接:依次尝试 1.整体就是链接 2.markdown链接格式 3.正文中任意URL(兼容反引号/文字包裹的情况)
|
|
|
const trimmedContent = content.trim()
|
|
const trimmedContent = content.trim()
|
|
|
const directUrlMatch = trimmedContent.match(/^(https?:\/\/\S+)$/)
|
|
const directUrlMatch = trimmedContent.match(/^(https?:\/\/\S+)$/)
|
|
|
- const urlMatch = directUrlMatch
|
|
|
|
|
|
|
+ const mdUrlMatch = directUrlMatch
|
|
|
? null
|
|
? null
|
|
|
: trimmedContent.replace(/\n/g, '').match(/\[.*?\]\((https?:\/\/.*?)\)/)
|
|
: trimmedContent.replace(/\n/g, '').match(/\[.*?\]\((https?:\/\/.*?)\)/)
|
|
|
- const imageUrl = directUrlMatch ? directUrlMatch[1] : (urlMatch ? urlMatch[1] : '')
|
|
|
|
|
|
|
+ const anyUrlMatch = directUrlMatch || mdUrlMatch
|
|
|
|
|
+ ? null
|
|
|
|
|
+ : trimmedContent.match(/https?:\/\/[^\s'"`<>()【】,。;:!?]+/)
|
|
|
|
|
+ const rawUrl = directUrlMatch
|
|
|
|
|
+ ? directUrlMatch[1]
|
|
|
|
|
+ : mdUrlMatch
|
|
|
|
|
+ ? mdUrlMatch[1]
|
|
|
|
|
+ : (anyUrlMatch ? anyUrlMatch[1] : '')
|
|
|
|
|
+ // 去掉URL尾部可能带的标点
|
|
|
|
|
+ const imageUrl = rawUrl.replace(/[.,;:!?)'"`。,;:!?)]+$/, '')
|
|
|
|
|
|
|
|
// 判断当前页面是否是工具页(含frame元素)
|
|
// 判断当前页面是否是工具页(含frame元素)
|
|
|
const isToolPage = (currentSlide.value?.elements || []).some((el: any) => el.type === 'frame')
|
|
const isToolPage = (currentSlide.value?.elements || []).some((el: any) => el.type === 'frame')
|