Skip to content
Snippets Groups Projects
Unverified Commit 0919f700 authored by Douglas Fabris's avatar Douglas Fabris Committed by GitHub
Browse files

fix: Unexpected error when loading webdav files (#35257)

parent 5294fed5
No related branches found
No related tags found
No related merge requests found
---
'@rocket.chat/meteor': patch
---
Fixes an issue where an unexpected error is thrown when webdav node doesn't have the mime parameter
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');
});
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';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment