@@ -349,14 +349,22 @@ function uploadFiles(
349349 ) ;
350350
351351 // First, delete any files that don't exist in our list of files.
352- const items = Object . keys ( files ) ;
353352 for ( const file of inner_message . files ) {
353+ if ( ! file . path || ! file . data ) continue ;
354+
355+ // Sometimes, the returned path can start with a /,
356+ // but our format doesn't have a leading /, so we need
357+ // to remove it to normalize it.
358+ const fixedPath = file . path . startsWith ( "/" )
359+ ? file . path . substring ( 1 )
360+ : file . path ;
361+
354362 // If our list of new items doesn't include this item,
355363 // delete it.
356- if ( ! items . includes ( file . path ) ) {
364+ if ( ! ( fixedPath in files ) ) {
357365 const delete_file_inner =
358366 ProxyInDeleteFile . DeleteFile . toBinary ( {
359- path : file . path ,
367+ path : fixedPath ,
360368 } ) ;
361369
362370 const delete_file = ProxyInMain . Main . toBinary ( {
@@ -365,15 +373,10 @@ function uploadFiles(
365373 } ) ;
366374
367375 ws . send ( delete_file ) ;
368- }
369- }
370-
371- // Next, we'll filter out any items that already exist in the container.
372- for ( const file of inner_message . files ) {
373- // If the item already exists in the container,
374- // no need to re-upload it.
375- if ( files [ file . path ] === file . data ?. toString ( ) ) {
376- delete files [ file . path ] ;
376+ } else if ( files [ fixedPath ] === file . data ?. toString ( ) ) {
377+ // If the item already exists in the container,
378+ // no need to re-upload it.
379+ delete files [ fixedPath ] ;
377380 }
378381 }
379382
0 commit comments