diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue
index 1f82bfc0..f5ff655c 100644
--- a/src/views/chat/components/Message/Text.vue
+++ b/src/views/chat/components/Message/Text.vue
@@ -50,10 +50,46 @@ const wrapClass = computed(() => {
]
})
+function getVideoPreviewer({ type, vid }: { type: 'bilibili' | 'youtube'; vid: string }) {
+ let previewer = ''
+ if (type === 'bilibili') {
+ previewer = ``
+ }
+ else if (type === 'youtube') {
+ previewer = ``
+ }
+ else {
+ // 更新其他视频网站的在线预览
+ }
+ return `
${previewer}
`
+}
+
+function generateVideoPreviewerText(text: string) {
+ if (!text)
+ return ''
+ // 这里截取视频网站和vid
+ const reg = /(www\.youtube\.com\/watch\?v\=[^\s\)]+)|(www\.bilibili\.com\/video\/[^\s\)]+)/g
+ const links = text.match(reg)
+ return links
+ ? links?.map((link) => {
+ if (link.includes('youtube')) {
+ const pattern = /watch\?v\=([^\s\&\)]+)/
+ const matchResult = link.match(pattern)
+ return matchResult ? getVideoPreviewer({ type: 'youtube', vid: matchResult[1] }) : ''
+ }
+ else {
+ const pattern = /video\/(([^\s\/\?\)]+))/
+ const matchResult = link.match(pattern)
+ return matchResult ? getVideoPreviewer({ type: 'bilibili', vid: matchResult[1] }) : ''
+ }
+ }).join('\n')
+ : ''
+}
+
const text = computed(() => {
const value = props.text ?? ''
if (!props.asRawText)
- return mdi.render(value)
+ return mdi.render(value) + generateVideoPreviewerText(value)
return value
})