import { Inject , Injectable } from '@angular/core' ; import { InputFile } from '../interfaces/input-file' ; import { InputFileConfig } from '../interfaces/input-file-config' ; @ Injectable ( { providedIn : 'root' } ) export class InputFileService { constructor ( @ Inject ( 'config' ) private _config ) { } get config ( ) { return this . _config ; } param files public limitGuard ( files , fileLimit ) { return files . length < fileLimit ; } param file param sizeLimit public sizeGuard ( file , sizeLimit ) { return ! sizeLimit || file . size < sizeLimit * 1024 * 1024 ; } param file param fileAccept public typeGuard ( file , fileAccept ) { let enabled = fileAccept == null ; if ( fileAccept ) { const accept = fileAccept . replace ( '*' , '' ) ; const types = accept . split ( ',' ) ; for ( const type of types ) { if ( file . type . startsWith ( type ) || ( type . charAt ( 0 ) === '.' && file . name != null && file . name . endsWith ( type ) ) ) { enabled = true ; break ; } } } return enabled ; } }