diff --git a/web/src/components/Chat/ChatContent.tsx b/web/src/components/Chat/ChatContent.tsx index a785ea49..509004b0 100644 --- a/web/src/components/Chat/ChatContent.tsx +++ b/web/src/components/Chat/ChatContent.tsx @@ -8,12 +8,11 @@ import { type FC, useRef, useEffect, useState } from 'react' import clsx from 'clsx' import Markdown from '@/components/Markdown' import type { ChatContentProps } from './types' -import { Spin, Image, Flex, Button } from 'antd' +import { Spin, Flex, Button } from 'antd' import { SoundOutlined } from '@ant-design/icons' import { useTranslation } from 'react-i18next' -import AudioPlayer from './AudioPlayer' -import VideoPlayer from './VideoPlayer' +import MessageFiles from './MessageFiles' const getFileUrl = (file: any) => { return file.thumbUrl || file.url || (file.originFileObj ? URL.createObjectURL(file.originFileObj) : undefined) @@ -149,72 +148,7 @@ const ChatContent: FC = ({ {labelFormat(item)} } - {item?.meta_data?.files && item.meta_data?.files.length > 0 && - {item.meta_data?.files?.map((file) => { - if (file.type.includes('image')) { - return ( -
- {file.name} -
- ) - } - if (file.type.includes('video')) { - return ( -
- {/*
- ) - } - if (file.type.includes('audio')) { - return ( -
- -
- ) - } - - const documentType = (file.file_type || file.type)?.split('/') - return ( - handleDownload(file)} - > -
-
-
{file.name}
-
{documentType?.[documentType.length - 1]} · {file.size}
-
-
- ) - })} -
} + {/* Message bubble */}
+ file.thumbUrl || file.url || (file.originFileObj ? URL.createObjectURL(file.originFileObj) : undefined) + +const DOC_ICONS: [string[], string][] = [ + [['pdf'], "rb:bg-[url('@/assets/images/file/pdf.svg')]"], + [['excel', 'spreadsheetml.sheet', 'xls', 'xlsx'], "rb:bg-[url('@/assets/images/file/excel.svg')]"], + [['csv'], "rb:bg-[url('@/assets/images/file/csv.svg')]"], + [['html'], "rb:bg-[url('@/assets/images/file/html.svg')]"], + [['json'], "rb:bg-[url('@/assets/images/file/json.svg')]"], + [['ppt'], "rb:bg-[url('@/assets/images/file/ppt.svg')]"], + [['markdown'], "rb:bg-[url('@/assets/images/file/md.svg')]"], + [['text'], "rb:bg-[url('@/assets/images/file/txt.svg')]"], + [['doc', 'docx', 'word', 'wordprocessingml.document'], "rb:bg-[url('@/assets/images/file/word.svg')]"], +] + +const getDocIcon = (parts: string[]) => { + const match = DOC_ICONS.find(([keys]) => keys.some(k => parts.includes(k))) + return match ? match[1] : "rb:bg-[url('@/assets/images/file/txt.svg')]" +} + +interface MessageFilesProps { + files: any[] + contentClassNames?: string | Record + onDownload: (file: any) => void +} + +const MessageFiles = ({ files, contentClassNames, onDownload }: MessageFilesProps) => { + if (!files?.length) return null + return ( + + {files.map((file) => { + const key = file.url || file.uid + if (file.type.includes('image')) { + return ( +
+ {file.name} +
+ ) + } + if (file.type.includes('video')) { + return ( +
+ +
+ ) + } + if (file.type.includes('audio')) { + return ( +
+ +
+ ) + } + const documentType = (file.file_type || file.type)?.split('/') + return ( + onDownload(file)} + > +
+
+
{file.name}
+
+ {documentType?.[documentType.length - 1]} · {file.size} +
+
+ + ) + })} + + ) +} + +export default MessageFiles