// lib/fileIcon.ts:由 lib/utils.ts 按职责拆分(实现未改) export const isImageFile = (filename: string): boolean => /\.(jpg|jpeg|png|gif|bmp|webp|svg|ico|tiff|tif)$/i.test(filename); export const isPdfFile = (filename: string): boolean => /\.pdf$/i.test(filename); export const isVideoFile = (filename: string): boolean => /\.(mp4|webm|ogg|mov|avi|mkv|flv|wmv|m4v)$/i.test(filename); export const isAudioFile = (filename: string): boolean => /\.(mp3|wav|ogg|aac|flac|wma|m4a|opus)$/i.test(filename); export const isMdFile = (filename: string): boolean => /\.md$/i.test(filename); export const isWordFile = (filename: string): boolean => /\.(doc|docx)$/i.test(filename); export const isOldDocFile = (filename: string): boolean => /\.doc$/i.test(filename) && !/\.docx$/i.test(filename); export const isExcelFile = (filename: string): boolean => /\.(xls|xlsx)$/i.test(filename); export const isCsvFile = (filename: string): boolean => /\.csv$/i.test(filename); // —— CAD —— // 当前只支持 .dxf(明文交换格式,可本地解析渲染); // .dwg(专有二进制,需服务端转换)与 .mxweb(依赖 mxcad 及其配套服务)暂不预览,由 fetchPreviewFile 返回 null 回退为下载。 export const isDxfFile = (filename: string): boolean => /\.dxf$/i.test(filename); export const isTextFile = (filename: string): boolean => /\.(txt|md|json|csv|xml|yaml|yml|log|ini|toml|cfg|conf|env|gitignore|dockerignore|editorconfig|prettierrc|eslintrc|babelrc|properties|sh|bat|ps1|cmd|bash|zsh|fish|sql|graphql|proto|js|ts|jsx|tsx|vue|css|scss|sass|less|html|htm|svelte|py|java|kt|kts|c|cpp|h|hpp|cc|cxx|cs|go|rs|rb|php|swift|m|mm|r|R|lua|pl|pm|hs|ex|exs|erl|clj|scala|dart|zig|nim|v|sol|tf|hcl|gradle|cmake|makefile|mk)$/i.test( filename ); export const getFileExtension = (filename: string): string => { const match = filename.match(/\.([^.]+)$/); return match ? `.${match[1]}`.toUpperCase() : ''; }; // CSS 变量里的图片地址(图标统一走 var(--img-chat-*)):带缓存,避免每帧 getComputedStyle; // 主题切换时 html 的 class 变化,清空缓存重新取。模块级共享,各组件读到的都是同一份文档级取值。 export const getFileIconVar = (filename: string): string => { if (isMdFile(filename)) return 'var(--img-chat-file-md-icon)'; if (isPdfFile(filename)) return 'var(--img-chat-file-pdf-icon)'; if (isWordFile(filename)) return 'var(--img-chat-file-word-icon)'; if (isExcelFile(filename) || isCsvFile(filename)) return 'var(--img-chat-file-excel-icon)'; if (isImageFile(filename)) return 'var(--img-chat-file-img-icon)'; if (isTextFile(filename)) return 'var(--img-chat-file-txt-icon)'; return 'var(--img-chat-attach-icon)'; }; // 按文件类型拉取远端文件内容并构造右侧面板预览对象(消息内文件卡片与胶囊面板共用)。 // 不支持的格式返回 null,由调用方回退为直接下载