Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/uikit-utils/src/__tests__/shared/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('getFileType', function () {
expect(getFileType('application/zip')).toBe('file');
expect(getFileType('application/x-gzip')).toBe('file');
expect(getFileType('text/plain')).toBe('file');
// HEIC/HEIF should be treated as file (not universally supported for inline display)
expect(getFileType('image/heic')).toBe('file');
expect(getFileType('image/heif')).toBe('file');
});

it('should return the proper file type with file extension', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/uikit-utils/src/shared/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,21 @@ const EXTENSION_MIME_MAP = {
export const imageExtRegex = /jpeg|jpg|png|webp|gif/i;
export const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav|ogg/i;
export const videoExtRegex = /mov|vod|mp4|avi|mpeg|ogv/i;
// HEIC/HEIF should be treated as file, not image (not universally supported for inline display)
export const nonImageMimeSubtypes = /heic|heif/i;
export const getFileType = (extensionOrType: string) => {
const lowerCased = extensionOrType.toLowerCase();

// mime type
if (lowerCased.indexOf('/') > -1) {
const type = lowerCased.split('/')[0];
const [type, subtype] = lowerCased.split('/');
if (type === 'video') return 'video';
if (type === 'audio') return 'audio';
if (type === 'image') return 'image';
if (type === 'image') {
// HEIC/HEIF are not universally supported, treat as file
if (subtype?.match(nonImageMimeSubtypes)) return 'file';
return 'image';
}
return 'file';
}

Expand Down