diff --git a/.changeset/four-houses-doubt.md b/.changeset/four-houses-doubt.md new file mode 100644 index 0000000000000..a97638e63c4fb --- /dev/null +++ b/.changeset/four-houses-doubt.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes an issue where an unexpected error is thrown when webdav node doesn't have the mime parameter diff --git a/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.spec.ts b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.spec.ts new file mode 100644 index 0000000000000..b5138a69a7e4d --- /dev/null +++ b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.spec.ts @@ -0,0 +1,13 @@ +import { faker } from '@faker-js/faker'; + +import { getNodeIconType } from './getNodeIconType'; + +it('should return clip icon if file does not have mime type', () => { + const result = getNodeIconType(faker.system.fileName(), faker.system.fileType(), undefined); + expect(result.icon).toBe('clip'); +}); + +it('should return folder icon if file type is directory', () => { + const result = getNodeIconType(faker.system.fileName(), 'directory', undefined); + expect(result.icon).toBe('folder'); +}); diff --git a/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.ts b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.ts index 13c9e506dab0c..79230546fb8bc 100644 --- a/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.ts +++ b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/lib/getNodeIconType.ts @@ -1,5 +1,6 @@ import type { Keys as IconName } from '@rocket.chat/icons'; +// TODO: This function should be simplified, it only needs to return the icon name export const getNodeIconType = ( basename: string, fileType: string, @@ -13,20 +14,17 @@ export const getNodeIconType = ( extension = ''; } - if (!mime) { - throw new Error('mime is required'); - } - if (fileType === 'directory') { icon = 'folder'; type = 'directory'; - } else if (mime.match(/application\/pdf/)) { + } else if (mime?.match(/application\/pdf/)) { icon = 'file-pdf'; type = 'pdf'; - } else if (['application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.presentation'].includes(mime)) { + } else if (mime && ['application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.presentation'].includes(mime)) { icon = 'file-document'; type = 'document'; } else if ( + mime && [ 'application/vnd.ms-excel', 'application/vnd.oasis.opendocument.spreadsheet', @@ -35,7 +33,7 @@ export const getNodeIconType = ( ) { icon = 'file-sheets'; type = 'sheets'; - } else if (['application/vnd.ms-powerpoint', 'application/vnd.oasis.opendocument.presentation'].includes(mime)) { + } else if (mime && ['application/vnd.ms-powerpoint', 'application/vnd.oasis.opendocument.presentation'].includes(mime)) { icon = 'file-sheets'; type = 'ppt'; }