feat(wip): 支持視頻和文件

This commit is contained in:
CrescentLeaf
2025-10-01 01:08:52 +08:00
parent 73e795e29f
commit f436f84696

View File

@@ -33,10 +33,17 @@ const markedInstance = new marked.Marked({
return `<span>${text}</span>` return `<span>${text}</span>`
}, },
image({ text, href }) { image({ text, href }) {
if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) const type = /^(Video|File)=.*/.exec(text)?.[1] || 'Image'
return `<chat-image src="${href}" alt="${text}"></chat-image>`
if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) {
return ({
Image: `<chat-image src="${href}" alt="${text}"></chat-image>`,
Video: `<chat-video src="${href}" alt="${text}"></chat-video>`,
File: `<chat-file src="${href}" alt="${text}"></chat-file>`,
})?.[type] || ``
}
return `` return ``
} },
} }
}) })
@@ -178,6 +185,8 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
cachedFileNamesCount.current[name] = 1 cachedFileNamesCount.current[name] = 1
if (type.startsWith('image/')) if (type.startsWith('image/'))
insertText(`![圖片](${name})`) insertText(`![圖片](${name})`)
else if (type.startsWith('video/'))
insertText(`![Video=${name}](${name})`)
else else
insertText(`![File=${name}](${name})`) insertText(`![File=${name}](${name})`)
} }