@@ -630,26 +630,35 @@ <h2>Upload logs</h2>
630630 return [ ] ;
631631 }
632632 } ) . then ( mods => {
633- // For each mod's download link, perform a POST request
634- mods . forEach ( ( url , index ) => {
635- setTimeout ( ( ) => {
636- fetch ( start + "/api/mods/installfromurl" , {
637- method : "POST" ,
638- body : url
639- } )
640- . then ( postRes => {
641- if ( ! postRes . ok ) {
642- console . error ( `Failed to post link: ${ postRes . status } ${ postRes . statusText } ` ) ;
643- } else {
644- console . log ( `Successfully posted link: ${ url } ` ) ;
645- }
646- } )
647- . catch ( error => console . error ( "Error posting link:" , error ) ) ;
648- } , 200 * index ) ;
633+ // Create an array of promises for each mod's download link
634+ const requests = mods . map ( ( url , index ) => {
635+ return new Promise ( resolve => {
636+ setTimeout ( ( ) => {
637+ fetch ( start + "/api/mods/installfromurl" , {
638+ method : "POST" ,
639+ body : url
640+ } )
641+ . then ( postRes => {
642+ if ( ! postRes . ok ) {
643+ console . error ( `Failed to post link: ${ postRes . status } ${ postRes . statusText } ` ) ;
644+ } else {
645+ console . log ( `Successfully posted link: ${ url } ` ) ;
646+ }
647+ resolve ( ) ; // Resolve the promise when done
648+ } )
649+ . catch ( error => {
650+ console . error ( "Error posting link:" , error ) ;
651+ resolve ( ) ; // Resolve even if there's an error
652+ } ) ;
653+ } , 200 * index ) ;
654+ } ) ;
649655 } ) ;
656+
657+ // Wait for all requests to complete before changing location
658+ return Promise . all ( requests ) ;
650659 } ) . then ( ( ) => {
651- localStorage . openMainDefault = true
652- location = start + "/?tab=mods"
660+ localStorage . openMainDefault = true ;
661+ location = start + "/?tab=mods" ;
653662 } ) ;
654663 } )
655664 }
0 commit comments