Skip to content

Commit 5b06eca

Browse files
Merge pull request #81 from AltyFox/main
Fix flow to install individual QMODs from the core mods repo
2 parents b5fa181 + aa22042 commit 5b06eca

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/QuestAppVersionSwitcher/bin
22
/QuestAppVersionSwitcher/obj
33
/.idea
4-
/.vs
4+
/.vs
5+
/.vscode

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"dotnet.preferCSharpExtension": true
2+
"dotnet.preferCSharpExtension": true,
3+
"githubPullRequests.ignoredPullRequestBranches": [
4+
"main"
5+
]
36
}

QuestAppVersionSwitcher/Assets/html/flows/beat_saber_modding.html

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)