import { FileUploader , UploadContext } from '@remirror/core' ; import { FileAttributes } from '../file-extension' ; import { getDefaultFileAttrs } from './data-url-file-uploader' ; /**
 * Mock implementation of a FileUploader to test slow file uploads
 */ export function createSlowFileUploader ( ) { let file ; let aborted = false ; return { insert : ( f ) => { file = f ; return getDefaultFileAttrs ( file ) ; } , upload : async ( context ) => { const total = 1000 ; let loaded = 0 ; context . set ( 'total' , total ) ; context . set ( 'loaded' , loaded ) ; while ( loaded < total ) { if ( aborted ) { throw new Error ( 'Canceled' ) ; } await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ; loaded += Math . random ( ) * 40 ; loaded = Math . min ( total , loaded ) ; context . set ( 'loaded' , loaded ) ; } const url = URL . createObjectURL ( file ) ; return { ... getDefaultFileAttrs ( file ) , url } ; } , abort : ( ) : void => { aborted = true ; } , } ; }