From 901ee3a890af25f0b69c9f40407d2bf056f21cfc Mon Sep 17 00:00:00 2001 From: Henry Gross-Hellsen <6283258+cowpod@users.noreply.github.com> Date: Wed, 13 Nov 2024 01:45:24 -0800 Subject: [PATCH] fix forge installer wrong order, move url verification to client-side --- functions/chf.php | 12 ---- resources/js/page_modloaders.js | 98 ++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 51 deletions(-) delete mode 100644 functions/chf.php diff --git a/functions/chf.php b/functions/chf.php deleted file mode 100644 index 96dc348..0000000 --- a/functions/chf.php +++ /dev/null @@ -1,12 +0,0 @@ - { +async function fetch_forges() { $("#fetch-forge").attr("disabled", true); // $("#fetch-fabric").attr("disabled", true); // $("#fetch-neoforge").attr("disabled",true); $("#fetch-forge").html("Loading..."); var request = new XMLHttpRequest(); request.open('GET', './functions/forge-links.php'); - request.onreadystatechange = function() { - if (request.readyState == 4) { - if (request.status == 200) { - response = JSON.parse(this.response); - nof=0; - fiq=0; - for (var key in response) { - nof++; - chf(response[key]["link"],response[key]["name"],response[key]["id"],response[key]["mc"]); + request.onreadystatechange = async function() { + if (request.readyState == 4 && request.status == 200) { + response = JSON.parse(this.response); + + response = Object.fromEntries( + Object.entries(response).reverse() + ); + + $("#fetched-mods").show(); + console.log("ignore 404s, they're supposed to be suppressed/catched with onerror") + let onesix_404ed=false; + for (var key in response) { + // if below problematic version 1.6.1, AND we couldn't get 1.6.1, skip the rest + if (compareVersions(key,'1.6.0')<0 && onesix_404ed) { + continue; + } else { + try { + await chf(response[key]["link"],response[key]["name"],response[key]["id"],response[key]["mc"]); + } catch (e) { + console.log(`ignoring 404 #4: '${key}'`); + if (compareVersions(key,'1.6.0')<0) { + onesix_404ed=true; + } + } } } + + $("#fetch-forge").html("Show Forge Installer"); + // $("#fetch-forge").removeAttr("disabled"); + // $("#fetch-fabric").removeAttr("disabled"); + // $("#fetch-neoforge").removeAttr("disabled"); } } + request.send(); } // add item to installer list -function chf(link,name,id,mc) { - var chf = new XMLHttpRequest(); - chf.open('GET', "./functions/chf.php?link="+link); - chf.onreadystatechange = function() { - if (chf.readyState == 4) { - if (chf.status == 200) { - fiq++; - if (chf.response == "OK") { - $("#fetched-mods").show(); - $("#forge-table").append(` - - ${mc} - ${name} - ${link} - - - `); - if (fiq==nof) { - $("#fetch-forge").html("Show Forge Installer"); - // $("#fetch-forge").removeAttr("disabled"); - // $("#fetch-fabric").removeAttr("disabled"); - // $("#fetch-neoforge").removeAttr("disabled"); - } - } +async function chf(link,name,id,mc) { + return new Promise((resolve, reject) => { + fetch(link, { method:'HEAD' }) + .then(response=> { + if (response.status == 404) { + // console.log('ignoring 404 #1'); + reject(id); + } else if (response.status == 200) { + $("#forge-table").append(` + + ${mc} + ${name} + ${link} + + + `); + resolve(id); } - } - } - chf.send(); + }) + .catch(error=>{ + // console.log('ignoring 404 #2'); + reject(id); + }); + }).catch(error=>{ + // console.log('ignoring 404 #3'); + reject(id); + }); } // add item to installed list