import { FileIcon } from 'lucide-react' import { cn } from '../lib/utils' import { DocxIcon } from '../ui/icons/docx' import { PDFIcon } from '../ui/icons/pdf' import { SheetIcon } from '../ui/icons/sheet' import { TxtIcon } from '../ui/icons/txt' export type FileData = { filename: string mediaType: string // https://www.iana.org/assignments/media-types/media-types.xhtml url: string // can be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs). } const FileIconMap: Record = { csv: , pdf: , docx: , txt: , } export function ChatFile({ file, className, }: { file: FileData className?: string }) { const isImage = isImageFile(file) const fileExtension = getFileExtension(file.filename) const handleClick = () => { if (file.url) { window.open(file.url, '_blank', 'noopener,noreferrer') } } return (
{file.url && isImage ? ( uploaded-image ) : (
{FileIconMap[fileExtension] ?? }
)}
{file.filename}
) } // Helper function to check if file is an image function isImageFile(file: FileData): boolean { return file.mediaType.startsWith('image/') } // Helper function to get file extension function getFileExtension(fileName: string): string { return fileName.split('.').pop()?.toLowerCase() ?? '' }