2024-08-03 02:41:27 -07:00
|
|
|
async function fetchPackages(uri) {
|
|
|
|
let statusText = document.getElementById("statusText");
|
|
|
|
statusText.innerHTML = "Fetching packages, please wait...";
|
|
|
|
let response = await fetch(uri, {
|
|
|
|
method: "GET"
|
|
|
|
})
|
|
|
|
let responseText = await response.text()
|
2024-08-06 08:16:01 -07:00
|
|
|
if (response.status === 200) {
|
|
|
|
console.log('Response:', responseText);
|
|
|
|
try {
|
|
|
|
const parsedDocument = new DOMParser().parseFromString(responseText, "text/html");
|
|
|
|
const linksNodeList = parsedDocument.querySelectorAll("a");
|
|
|
|
linksNodeList.forEach((link) => {
|
|
|
|
const linkText = link.innerHTML.trim();
|
|
|
|
const forbiddenLinks = ["Name", "Last modified", "Size", "Description", "Parent Directory", "repodata/"];
|
|
|
|
if (!forbiddenLinks.includes(linkText) && !linkText.endsWith(".html")) {
|
|
|
|
const packageLink = document.createElement("a");
|
|
|
|
const newRedirect = uri + "/" + link.href.split("/").pop();
|
|
|
|
packageLink.href = newRedirect;
|
|
|
|
packageLink.innerHTML = linkText;
|
|
|
|
packageLink.className = "package";
|
|
|
|
packageLink.target = "_blank";
|
|
|
|
document.getElementById("packages").appendChild(packageLink);
|
|
|
|
console.log('Original URL:', link.href);
|
|
|
|
console.log('Modified URL:', newRedirect);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (document.getElementById("packages").childElementCount === 0) {
|
|
|
|
statusText.innerHTML = "Nothing here yet!";
|
|
|
|
} else {
|
|
|
|
statusText.remove()
|
2024-08-03 02:41:27 -07:00
|
|
|
}
|
2024-08-06 08:16:01 -07:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Parsing error:', e);
|
|
|
|
statusText.innerHTML = "Failed to fetch packages. Please try again later.";
|
|
|
|
}
|
|
|
|
} else if (response.status === 404) {
|
|
|
|
console.error('Response:', responseText);
|
|
|
|
statusText.innerHTML = "Nothing here yet!";
|
|
|
|
} else {
|
|
|
|
console.error('Response:', responseText);
|
2024-08-03 02:41:27 -07:00
|
|
|
statusText.innerHTML = "Failed to fetch packages. Please try again later.";
|
|
|
|
}
|
2024-08-03 07:33:14 -07:00
|
|
|
}
|