import { isImage , isSupportedText , isPDF , isVideo , isFont , isExcel , isICS } from '@proton/shared/lib/helpers/mimetype' ; import { classnames } from '../../helpers/component' ; import { IconProps } from '../icon/Icon' ; import MimeIcon from '../icon/MimeIcon' ; const iconsMap = { Folder : { name : 'folder' } , 'application/x-rar-compressed' : { name : 'zip' } , 'application/x-zip-compressed' : { name : 'zip' } , 'application/zip' : { name : 'zip' } , 'application/x-7z-compressed' : { name : 'zip' } , 'application/x-arj' : { name : 'zip' } , 'application/x-debian-package' : { name : 'zip' } , 'application/octet-stream' : { name : 'zip' } , 'application/x-redhat-package-manager' : { name : 'zip' } , 'application/x-rpm' : { name : 'zip' } , 'application/vnd.rar' : { name : 'zip' } , 'application/gzip' : { name : 'zip' } , 'application/x-gzip' : { name : 'zip' } , 'application/x-compress' : { name : 'zip' } , 'application/vnd.apple.installer+xml' : { name : 'zip' } , 'application/msword' : { name : 'doc' } , 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : { name : 'doc' , } , 'application/vnd.ms-powerpoint' : { name : 'ppt' } , 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : { name : 'ppt' , } , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' : { name : 'xls' } , 'application/vnd.oasis.opendocument.spreadsheet' : { name : 'xls' } , 'application/vnd.oasis.opendocument.presentation' : { name : 'ppt' } , 'application/xliff+xml' : { name : 'xml' } , 'application/xml' : { name : 'xml' } , 'text/html' : { name : 'xml' } , 'application/xhtml+xml' : { name : 'xml' } , 'application/pgp-keys' : { name : 'keytrust' } , 'application/rtf' : { name : 'text' } , 'application/x-tex' : { name : 'text' } , 'application/vnd.oasis.opendocument.text' : { name : 'text' } , 'application/vnd.wordperfect' : { name : 'text' } , 'application/vnd.ms-fontobject' : { name : 'font' } , 'application/font-sfnt' : { name : 'font' } , 'application/vnd.oasis.opendocument.formula-template' : { name : 'font' } , } ; const getIconName = ( mimeType ) => { let name = 'unknown' ; if ( iconsMap [ mimeType ] ) { name = iconsMap [ mimeType ] . name ; } else if ( isImage ( mimeType ) ) { name = 'image' ; } else if ( mimeType === 'text/xml' ) { name = 'xml' ; } else if ( isICS ( mimeType ) ) { name = 'calendar' ; } else if ( isSupportedText ( mimeType ) ) { name = 'text' ; } else if ( isPDF ( mimeType ) ) { name = 'pdf' ; } else if ( isVideo ( mimeType ) ) { name = 'video' ; } else if ( isFont ( mimeType ) ) { name = 'font' ; } else if ( isExcel ( mimeType ) ) { name = 'xls' ; } return name ; } ; interface Props extends Omit < IconProps , 'name' > { mimeType : string ; className ? : string ; } /**
 * Component to render SVG file icons.
 * It's wrapper around MimeIcon component which finds the proper icon
 * name based on the mime type.
 */ const FileIcon = ( { mimeType , className , ... rest } ) => { const name = getIconName ( mimeType ) ; return < MimeIcon name = { name } className = { classnames ( [ 'flex-item-noshrink' , className ] ) } { ... rest } />; } ; export default FileIcon ;