@@ -232,7 +232,8 @@ export interface State<M extends Meta, B extends Body>
232232 details ?: string | Record < string , string > | null
233233 } >
234234 plugins : Plugins
235- totalProgress : number
235+ totalProgress : number // todo remove backward compat
236+ progress : number | null
236237 companion ?: Record < string , string >
237238}
238239
@@ -361,6 +362,7 @@ type OmitFirstArg<T> = T extends [any, ...infer U] ? U : never
361362
362363const defaultUploadState = {
363364 totalProgress : 0 ,
365+ progress : null ,
364366 allowNewUpload : true ,
365367 error : null ,
366368 recoveredState : null ,
@@ -758,7 +760,7 @@ export class Uppy<
758760 isUploadInProgress : boolean
759761 isSomeGhost : boolean
760762 } {
761- const { files : filesObject , totalProgress, error } = this . getState ( )
763+ const { files : filesObject , progress : totalProgress , error } = this . getState ( )
762764 const files = Object . values ( filesObject )
763765
764766 const inProgressFiles : UppyFile < M , B > [ ] = [ ]
@@ -1445,15 +1447,15 @@ export class Uppy<
14451447 progress . bytesTotal > 0
14461448 ) ?
14471449 Math . round ( ( progress . bytesUploaded / progress . bytesTotal ) * 100 )
1448- : 0 ,
1450+ : undefined ,
14491451 }
14501452
14511453 if ( fileInState . progress . uploadStarted != null ) {
14521454 this . setFileState ( file . id , {
14531455 progress : {
14541456 ...fileInState . progress ,
1455- bytesUploaded : progress . bytesUploaded ,
14561457 ...newProgress ,
1458+ bytesUploaded : progress . bytesUploaded ,
14571459 } ,
14581460 } )
14591461 } else {
@@ -1469,12 +1471,19 @@ export class Uppy<
14691471 }
14701472
14711473 #updateTotalProgress( ) {
1472- let totalProgress = Math . round ( this . #calculateTotalProgress( ) * 100 )
1473- if ( totalProgress > 100 ) totalProgress = 100
1474- else if ( totalProgress < 0 ) totalProgress = 0
1474+ const totalProgress = this . #calculateTotalProgress( )
1475+ let totalProgressPercent : number | null = null ;
1476+ if ( totalProgress != null ) {
1477+ totalProgressPercent = Math . round ( totalProgress * 100 )
1478+ if ( totalProgressPercent > 100 ) totalProgressPercent = 100
1479+ else if ( totalProgressPercent < 0 ) totalProgressPercent = 0
1480+ }
14751481
1476- this . emit ( 'progress' , totalProgress )
1477- this . setState ( { totalProgress } )
1482+ this . emit ( 'progress' , totalProgressPercent ?? 0 ) // todo remove `?? 0` in next major
1483+ this . setState ( {
1484+ totalProgress : totalProgressPercent ?? 0 , // todo remove backward compat in next major
1485+ progress : totalProgressPercent ,
1486+ } )
14781487 }
14791488
14801489 // ___Why throttle at 500ms?
@@ -1512,35 +1521,31 @@ export class Uppy<
15121521 return 0
15131522 }
15141523
1515- const sizedFiles = filesInProgress . filter (
1516- ( file ) => file . progress . bytesTotal != null ,
1517- )
1518- const unsizedFiles = filesInProgress . filter (
1519- ( file ) => file . progress . bytesTotal == null ,
1524+ const sizedFilesInProgress = filesInProgress . filter (
1525+ ( file ) => file . progress . bytesTotal != null && file . progress . bytesTotal !== 0 ,
15201526 )
15211527
1522- if ( sizedFiles . length === 0 ) {
1523- const totalUnsizedProgress = unsizedFiles . reduce (
1524- ( acc , file ) => acc + ( file . progress . percentage ?? 0 ) / 100 ,
1525- 0 ,
1526- )
1528+ if ( sizedFilesInProgress . length === 0 ) {
1529+ return null // we don't have any files that we can know the percentage progress of
1530+ }
15271531
1528- return totalUnsizedProgress / unsizedFiles . length
1532+ if ( sizedFilesInProgress . every ( ( file ) => file . progress . uploadComplete ) ) {
1533+ // If every uploading file is complete, and we're still getting progress, it means either
1534+ // 1. there's a bug somewhere in some progress reporting code (maybe not even ours)
1535+ // and we're still getting progress, so let's just ignore it
1536+ // 2. there are files with unknown size (bytesTotal == null), still uploading,
1537+ // and we cannot say anything about their progress
1538+ // In any case, return null because it doesn't make any sense to show a progress
1539+ return null
15291540 }
15301541
1531- let totalFilesSize = sizedFiles . reduce ( ( acc , file ) => {
1532- return ( acc + ( file . progress . bytesTotal ?? 0 ) ) as number
1533- } , 0 )
1534- const averageSize = totalFilesSize / sizedFiles . length
1535- totalFilesSize += averageSize * unsizedFiles . length
1542+ const totalFilesSize = sizedFilesInProgress . reduce ( ( acc , file ) => (
1543+ acc + ( file . progress . bytesTotal ?? 0 )
1544+ ) , 0 )
15361545
1537- let totalUploadedSize = 0
1538- sizedFiles . forEach ( ( file ) => {
1539- totalUploadedSize += file . progress . bytesUploaded || 0
1540- } )
1541- unsizedFiles . forEach ( ( file ) => {
1542- totalUploadedSize += averageSize * ( ( file . progress . percentage ?? 0 ) / 100 )
1543- } )
1546+ const totalUploadedSize = sizedFilesInProgress . reduce ( ( acc , file ) => (
1547+ acc + ( file . progress . bytesUploaded || 0 )
1548+ ) , 0 )
15441549
15451550 return totalFilesSize === 0 ? 0 : totalUploadedSize / totalFilesSize
15461551 }
@@ -1628,7 +1633,6 @@ export class Uppy<
16281633 progress : {
16291634 uploadStarted : Date . now ( ) ,
16301635 uploadComplete : false ,
1631- percentage : 0 ,
16321636 bytesUploaded : 0 ,
16331637 bytesTotal : file . size ,
16341638 } as FileProgressStarted ,
0 commit comments