Files
dify/web/app/components/workflow/skill/utils/file-utils.ts
yyh cab33d440b refactor(skill): remove Office file special handling, merge into unsupported
Remove the Office file placeholder that only showed "Preview will be
supported in a future update" without any download option. Office files
(pdf, doc, docx, xls, xlsx, ppt, pptx) now fall through to the generic
"unsupported file" handler which provides a download button.

Removed:
- OfficeFilePlaceholder component
- isOfficeFile function and OFFICE_EXTENSIONS constant
- isOffice flag from useFileTypeInfo hook
- i18n keys for officePlaceholder

This simplifies the file type handling to just three categories:
- Editable: markdown, code, text files → editor
- Previewable: image, video files → media preview
- Everything else: download button
2026-01-19 23:39:32 +08:00

71 lines
2.0 KiB
TypeScript

import { FileAppearanceTypeEnum } from '@/app/components/base/file-uploader/types'
const MARKDOWN_EXTENSIONS = ['md', 'markdown', 'mdx']
const CODE_EXTENSIONS = ['json', 'yaml', 'yml', 'toml', 'js', 'jsx', 'ts', 'tsx', 'py', 'schema']
const TEXT_EXTENSIONS = ['txt', 'log', 'ini', 'env']
const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico']
const VIDEO_EXTENSIONS = ['mp4', 'mov', 'webm', 'mpeg', 'mpg', 'm4v', 'avi']
export function getFileExtension(name?: string, extension?: string): string {
if (extension)
return extension.toLowerCase()
if (!name)
return ''
return name.split('.').pop()?.toLowerCase() ?? ''
}
export function getFileIconType(name: string): FileAppearanceTypeEnum {
const extension = name.split('.').pop()?.toLowerCase() ?? ''
if (MARKDOWN_EXTENSIONS.includes(extension))
return FileAppearanceTypeEnum.markdown
if (CODE_EXTENSIONS.includes(extension))
return FileAppearanceTypeEnum.code
return FileAppearanceTypeEnum.document
}
export function isMarkdownFile(extension: string): boolean {
return MARKDOWN_EXTENSIONS.includes(extension)
}
export function isCodeOrTextFile(extension: string): boolean {
return CODE_EXTENSIONS.includes(extension) || TEXT_EXTENSIONS.includes(extension)
}
export function isImageFile(extension: string): boolean {
return IMAGE_EXTENSIONS.includes(extension)
}
export function isVideoFile(extension: string): boolean {
return VIDEO_EXTENSIONS.includes(extension)
}
export function getFileLanguage(name: string): string {
const extension = name.split('.').pop()?.toLowerCase() ?? ''
const languageMap: Record<string, string> = {
md: 'markdown',
markdown: 'markdown',
mdx: 'markdown',
json: 'json',
jsonl: 'json',
yaml: 'yaml',
yml: 'yaml',
js: 'javascript',
jsx: 'javascript',
ts: 'typescript',
tsx: 'typescript',
py: 'python',
html: 'html',
css: 'css',
xml: 'xml',
sql: 'sql',
sh: 'shell',
bash: 'shell',
}
return languageMap[extension] ?? 'plaintext'
}