@@ -1371,38 +1371,47 @@ export class Uppy<
1371
1371
this . emit ( 'resume-all' )
1372
1372
}
1373
1373
1374
- async retryAll ( ) : Promise < UploadResult < M , B > | undefined > {
1375
- const updatedFiles = { ... this . getState ( ) . files }
1376
- const filesToRetry = Object . keys ( updatedFiles ) . filter ( ( file ) => {
1377
- return updatedFiles [ file ] . error
1374
+ #getFilesToRetry ( ) {
1375
+ const { files } = this . getState ( )
1376
+ return Object . keys ( files ) . filter ( ( file ) => {
1377
+ return files [ file ] . error
1378
1378
} )
1379
+ }
1379
1380
1380
- filesToRetry . forEach ( ( file ) => {
1381
- const updatedFile = {
1382
- ...updatedFiles [ file ] ,
1381
+ async #doRetryAll( ) : Promise < UploadResult < M , B > | undefined > {
1382
+ const filesToRetry = this . #getFilesToRetry( )
1383
+
1384
+ const updatedFiles = { ...this . getState ( ) . files }
1385
+ filesToRetry . forEach ( ( fileID ) => {
1386
+ updatedFiles [ fileID ] = {
1387
+ ...updatedFiles [ fileID ] ,
1383
1388
isPaused : false ,
1384
1389
error : null ,
1385
1390
}
1386
- updatedFiles [ file ] = updatedFile
1387
1391
} )
1392
+
1388
1393
this . setState ( {
1389
1394
files : updatedFiles ,
1390
1395
error : null ,
1391
1396
} )
1392
1397
1393
- this . emit ( 'retry-all' , Object . values ( updatedFiles ) )
1398
+ this . emit ( 'retry-all' , this . getFilesByIds ( filesToRetry ) )
1394
1399
1395
1400
if ( filesToRetry . length === 0 ) {
1396
- return Promise . resolve ( {
1401
+ return {
1397
1402
successful : [ ] ,
1398
1403
failed : [ ] ,
1399
- } )
1404
+ }
1400
1405
}
1401
1406
1402
1407
const uploadID = this . #createUpload( filesToRetry , {
1403
1408
forceAllowNewUpload : true , // create new upload even if allowNewUpload: false
1404
1409
} )
1405
- const result = await this . #runUpload( uploadID )
1410
+ return this . #runUpload( uploadID )
1411
+ }
1412
+
1413
+ async retryAll ( ) : Promise < UploadResult < M , B > | undefined > {
1414
+ const result = await this . #doRetryAll( )
1406
1415
this . emit ( 'complete' , result ! )
1407
1416
return result
1408
1417
}
@@ -2248,44 +2257,22 @@ export class Uppy<
2248
2257
2249
2258
let { files } = this . getState ( )
2250
2259
2251
- // Check if we have files with errors (for retry behavior)
2252
- const filesToRetry = Object . keys ( files ) . filter (
2253
- ( fileID ) => files [ fileID ] . error ,
2254
- )
2255
- const hasFilesToRetry = filesToRetry . length > 0
2256
-
2257
- // If we have files to retry, behave like retryAll() and ignore any new files
2258
- if ( hasFilesToRetry ) {
2259
- const updatedFiles = { ...files }
2260
- filesToRetry . forEach ( ( fileID ) => {
2261
- updatedFiles [ fileID ] = {
2262
- ...updatedFiles [ fileID ] ,
2263
- isPaused : false ,
2264
- error : null ,
2265
- }
2266
- } )
2260
+ // retry any failed files from a previous upload() call
2261
+ const filesToRetry = this . #getFilesToRetry( )
2262
+ if ( filesToRetry . length > 0 ) {
2263
+ const retryResult = await this . #doRetryAll( ) // we don't want the complete event to fire
2267
2264
2268
- this . setState ( {
2269
- files : updatedFiles ,
2270
- error : null ,
2271
- } )
2272
-
2273
- this . emit ( 'retry-all' , this . getFilesByIds ( filesToRetry ) )
2274
-
2275
- const uploadID = this . #createUpload( filesToRetry , {
2276
- forceAllowNewUpload : true , // create new upload even if allowNewUpload: false
2277
- } )
2278
- const result = await this . #runUpload( uploadID )
2279
2265
const hasNewFiles =
2280
2266
this . getFiles ( ) . filter ( ( file ) => file . progress . uploadStarted == null )
2281
2267
. length > 0
2282
2268
2269
+ // if no new files, make it idempotent and return
2283
2270
if ( ! hasNewFiles ) {
2284
- this . emit ( 'complete' , result ! )
2285
-
2286
- return result
2271
+ this . emit ( 'complete' , retryResult ! )
2272
+ return retryResult
2287
2273
}
2288
- files = this . getState ( ) . files
2274
+ // reload files which might have changed after retry
2275
+ ; ( { files } = this . getState ( ) )
2289
2276
}
2290
2277
2291
2278
// If no files to retry, proceed with original upload() behavior for new files
0 commit comments