@@ -607,16 +607,62 @@ <h2>Upload logs</h2>
607607 }
608608
609609 var patchReport = { }
610+ var isInstallingCores = false ;
610611
611612 function InstallCoreModsAndGetMods ( ) {
613+ if ( isInstallingCores ) return ;
614+ isInstallingCores = true ;
612615 UpdateModdedStatus ( ) . then ( res => {
613- fetch ( start + `/api/mods/installfromurl` , {
614- method : "POST" ,
615- body : `https://raw.githubusercontent.com/QuestPackageManager/bs-coremods/main/core_mods.json?${ new Date ( ) . getTime ( ) } `
616- } ) . then ( res => {
617- localStorage . openMainDefault = true
618- location = start + "/?tab=mods"
616+ fetch ( `https://raw.githubusercontent.com/QuestPackageManager/bs-coremods/main/core_mods.json?${ new Date ( ) . getTime ( ) } ` ) . then ( res => {
617+ if ( ! res . ok ) {
618+ console . error ( `Failed to fetch core mods: ${ res . status } ${ res . statusText } ` ) ;
619+ }
620+ return res . json ( ) ;
619621 } )
622+ . then ( data => {
623+ // Find the mods for the specified version
624+ const versionData = data [ moddedStatus . version ] ;
625+
626+ if ( versionData && versionData . mods ) {
627+ // Extract download links for each mod
628+ const downloadLinks = versionData . mods . map ( mod => mod . downloadLink ) ;
629+ console . log ( `Download links for version ${ moddedStatus . version } :` , downloadLinks ) ;
630+ return downloadLinks ;
631+ } else {
632+ console . log ( `No mods found for version ${ moddedStatus . version } ` ) ;
633+ return [ ] ;
634+ }
635+ } ) . then ( mods => {
636+ // Create an array of promises for each mod's download link
637+ const requests = mods . map ( ( url , index ) => {
638+ return new Promise ( resolve => {
639+ setTimeout ( ( ) => {
640+ fetch ( start + "/api/mods/installfromurl" , {
641+ method : "POST" ,
642+ body : url
643+ } )
644+ . then ( postRes => {
645+ if ( ! postRes . ok ) {
646+ console . error ( `Failed to post link: ${ postRes . status } ${ postRes . statusText } ` ) ;
647+ } else {
648+ console . log ( `Successfully posted link: ${ url } ` ) ;
649+ }
650+ resolve ( ) ; // Resolve the promise when done
651+ } )
652+ . catch ( error => {
653+ console . error ( "Error posting link:" , error ) ;
654+ resolve ( ) ; // Resolve even if there's an error
655+ } ) ;
656+ } , 200 * index ) ;
657+ } ) ;
658+ } ) ;
659+
660+ // Wait for all requests to complete before changing location
661+ return Promise . all ( requests ) ;
662+ } ) . then ( ( ) => {
663+ localStorage . openMainDefault = true ;
664+ location = start + "/?tab=mods" ;
665+ } ) ;
620666 } )
621667 }
622668
0 commit comments