From 18ca83d763b0d2289d075ea6c9a6d3903ec14cb0 Mon Sep 17 00:00:00 2001 From: zhaoying Date: Thu, 19 Mar 2026 10:12:33 +0800 Subject: [PATCH] fix(web): local file support preview --- web/src/components/Chat/ChatContent.tsx | 31 ++++++++++++------- .../FeaturesConfig/FileUploadSettingModal.tsx | 3 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/web/src/components/Chat/ChatContent.tsx b/web/src/components/Chat/ChatContent.tsx index 2f2552db..4295a7c7 100644 --- a/web/src/components/Chat/ChatContent.tsx +++ b/web/src/components/Chat/ChatContent.tsx @@ -2,15 +2,20 @@ * @Author: ZhaoYing * @Date: 2025-12-10 16:46:17 * @Last Modified by: ZhaoYing - * @Last Modified time: 2026-03-18 20:48:03 + * @Last Modified time: 2026-03-19 10:06:31 */ import { type FC, useRef, useEffect, useState } from 'react' import clsx from 'clsx' import Markdown from '@/components/Markdown' import type { ChatContentProps } from './types' -import { Spin, Divider, Space } from 'antd' +import { Spin, Divider, Space, Image, Flex } from 'antd' import { SoundOutlined } from '@ant-design/icons' + +const getFileUrl = (file: any) => { + return file.thumbUrl || file.url || (file.originFileObj ? URL.createObjectURL(file.originFileObj) : undefined) +} + /** * Chat Content Display Component * Responsible for rendering chat message list, supports different role message styles and auto-scrolling @@ -88,6 +93,10 @@ const ChatContent: FC = ({ } }, 0); }, [data]) + + const handleDownload = (file: any) => { + window.open(getFileUrl(file), '_blank') + } return (
{data.length === 0 @@ -108,31 +117,31 @@ const ChatContent: FC = ({ {labelFormat(item)}
} - {item.meta_data?.files && item.meta_data?.files.length > 0 &&
+ {item.meta_data?.files && item.meta_data?.files.length > 0 && {item.meta_data?.files?.map((file) => { if (file.type.includes('image')) { return (
- {file.name} + {file.name}
) } if (file.type.includes('video')) { return ( -
-
} +
} {/* Message bubble */}