fileSupport.ts 1.3 KB

12345678910111213141516171819202122232425
  1. export const DOC_EXTENSIONS = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'rtf', 'csv', 'txt', 'md', 'html', 'json', 'xml', 'odt', 'ods', 'odp'];
  2. export const CODE_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx', 'css', 'py', 'java', 'sql', 'cpp', 'h', 'go', 'rs', 'php', 'rb'];
  3. export const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'];
  4. export const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp', 'image/tiff'];
  5. export const KB_ALLOWED_EXTENSIONS = [...DOC_EXTENSIONS, ...CODE_EXTENSIONS, ...IMAGE_EXTENSIONS];
  6. export const GROUP_ALLOWED_EXTENSIONS = [...DOC_EXTENSIONS, ...CODE_EXTENSIONS, ...IMAGE_EXTENSIONS];
  7. export const isExtensionAllowed = (ext: string, type: 'kb' | 'group'): boolean => {
  8. const normalizedExt = ext.toLowerCase().replace('.', '');
  9. if (type === 'kb') {
  10. return KB_ALLOWED_EXTENSIONS.includes(normalizedExt);
  11. }
  12. return GROUP_ALLOWED_EXTENSIONS.includes(normalizedExt);
  13. };
  14. export const getSupportedFormatsLabel = (type: 'kb' | 'group'): string => {
  15. return 'PDF, Word, Excel, PPT, TXT, MD, Code(JS/TS/PY...), Images...';
  16. };
  17. export const isFormatSupportedForPreview = (filename: string): boolean => {
  18. const ext = filename.toLowerCase().split('.').pop() || '';
  19. return [...DOC_EXTENSIONS, ...IMAGE_EXTENSIONS].includes(ext);
  20. };