@@ -3584,26 +3584,31 @@ angular
3584
3584
var uploadPath = ctx . path ;
3585
3585
var container = ctx . container ;
3586
3586
var type = ctx . type ;
3587
+
3588
+ var progressHandler = _ . throttle ( function ( ctx ) {
3589
+ chunksProgress [ ctx . index ] = ctx . progress . loaded ;
3590
+ var progression = chunksProgress . reduce ( function ( m , v ) { return m + v ; } , 0 ) / file . size ;
3591
+ events . emit ( 'progress' , progression * 100 ) ;
3592
+ } , 100 ) ;
3593
+
3587
3594
var uploadChunksEvents = new EventEmitter ( ) ;
3588
3595
uploadChunksEvents . on ( 'start' , function ( ctx ) {
3589
3596
chunksProgress [ ctx . index ] = 0 ;
3590
3597
if ( ctx . cancel ) {
3591
3598
chunksCancel [ ctx . index ] = function ( ) { ctx . cancel ( ) ; } ;
3592
3599
}
3593
- uploadChunksEvents . on ( 'progress' , function ( ctx ) {
3594
- chunksProgress [ ctx . index ] = ctx . progress . loaded ;
3595
- var progression = chunksProgress . reduce ( function ( m , v ) { return m + v ; } , 0 ) / file . size ;
3596
- events . emit ( 'progress' , progression * 100 ) ;
3597
- } ) ;
3600
+ uploadChunksEvents . on ( 'progress' , progressHandler ) ;
3598
3601
} ) ;
3599
3602
uploadChunksEvents . on ( 'end' , function ( ) { fileOffset += chunkSize ; } ) ;
3600
3603
uploadChunksEvents . on ( 'end' , function ( ctx ) { delete chunksCancel [ ctx . index ] ; } ) ;
3604
+
3601
3605
var result = Promise
3602
3606
. map (
3603
3607
chunks ( file , { chunkSize : chunkSize , fileOffset : fileOffset } ) ,
3604
3608
function ( v ) { return uploadChunk ( v . chunk , v . index , uploadId , uploadPath , uploadChunksEvents ) ; } ,
3605
3609
{ concurrency : 3 }
3606
3610
) ;
3611
+
3607
3612
return result
3608
3613
. then ( function ( ) { return { uploadId : uploadId , uploadPath : uploadPath , container : container , type : type } ; } ) ;
3609
3614
} )
0 commit comments