import { Injectable } from '@angular/core' ; import { IFile } from '../../../../../../shared/models/mediaManager/IFile' ; @ Injectable ( ) export class FileIconService { param { IFile } file returns { string } fileToIcon ( file ) { return this . mimeTypeToIcon ( file . mimeType ) ; } param { string } mimeType returns { string } mimeTypeToIcon ( mimeType ) { mimeType = mimeType . toLowerCase ( ) ; if ( this . isArchive ( mimeType ) ) { return 'archive' ; } if ( this . isDocument ( mimeType ) ) { return 'book' ; } if ( this . isImage ( mimeType ) ) { return 'image' ; } if ( this . isPdf ( mimeType ) ) { return 'picture_as_pdf' ; } if ( this . isText ( mimeType ) ) { return 'code' ; } if ( this . isVideo ( mimeType ) ) { return 'movie' ; } return 'attachment' ; } param { string } mimeType returns { boolean } isArchive ( mimeType ) { const archives = [ 'application/x-bzip' , 'application/x-bzip2' , 'application/x-rar-compressed' , 'application/x-tar' , 'application/x-zip-compressed' , 'application/zip' , 'application/x-7z-compressed' , ] ; return archives . indexOf ( mimeType ) >= 0 ; } param { string } mimeType returns { boolean } isDocument ( mimeType ) { const documents = [ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' , ] ; return documents . indexOf ( mimeType ) >= 0 ; } param { string } mimeType returns { boolean } isImage ( mimeType ) { return mimeType . startsWith ( 'image' ) ; } param { string } mimeType returns { boolean } isPdf ( mimeType ) { return mimeType === 'application/pdf' ; } param { string } mimeType returns { boolean } isText ( mimeType ) { return mimeType . startsWith ( 'text' ) ; } param { string } mimeType returns { boolean } isVideo ( mimeType ) { return mimeType . startsWith ( 'video' ) ; } }