import { InjectionToken } from '@angular/core' ; import { Ajax } from './ajax' ; import { AuthorizeRequest , UploaderOptions } from './interfaces' ; import { Uploader } from './uploader' ; import { UploaderX } from './uploaderx' ; /**
 * Global Module Options
 */ export interface UploadxOptions extends UploaderOptions { defaultValue uploaderClass ? : UploaderClass ; defaultValue concurrency ? : number ; defaultValue autoUpload ? : boolean ; /**
     * File types the user can pick from the file input
     */ allowedTypes ? : string ; defaultValue multiple ? : boolean ; defaultValue storeIncompleteHours ? : number ; } export interface UploadxFactoryOptions extends UploadxOptions { endpoint : string ; autoUpload : boolean ; concurrency : number ; uploaderClass : UploaderClass ; authorize : AuthorizeRequest ; storeIncompleteHours : number ; } export type UploaderClass = new ( file , options , stateChange , ajax ) => Uploader ; const defaultOptions = { endpoint : '/upload' , autoUpload : true , concurrency : 2 , uploaderClass : UploaderX , authorize : ( req , token ) => { token && ( req . headers [ 'Authorization' ] = `Bearer ${ token }` ) ; return req ; } , storeIncompleteHours : 24 } ; export const UPLOADX_FACTORY_OPTIONS = new InjectionToken < UploadxFactoryOptions > ( 'uploadx.factory.options' , { providedIn : 'root' , factory : ( ) => defaultOptions } ) ; export const UPLOADX_OPTIONS = new InjectionToken < UploadxOptions > ( 'uploadx.options' ) ; export const iOSPatch = ( options ) => { if ( options . chunkSize || options . maxChunkSize ) { console . warn ( 'Detected iOS device, chunk uploads are problematic on this device.' ) ; return ; } console . warn ( 'Detected iOS device, chunk uploading and retries on errors are disabled.' ) ; options . chunkSize = 0 ; options . retryConfig = { shouldRetry : ( ) => false } ; } ;