add updater version 1.0.2
This commit is contained in:
1 parent
aa3addbeba
commit
6c642935cf
14 files changed
+2394
No files matched your search
+423
@@ -0,0 +1,423 @@
|
||||
<!doctype html>
|
||||
|
||||
<h3>PGA Modification Downloader for Minecraft - Notice: for internal (LAN) use only. NEVER expose to the internet!</h3>
|
||||
<inp>
|
||||
<p>Absolute Plugin/Mod Folder Path:</p>
|
||||
<p style="color: red"> Warning: Script removes all files excluding folders. Script ignores files that start with "!" in name as an override.</p>
|
||||
<input type="text" id="path"></input>
|
||||
<button onclick="set_path();">Set</button>
|
||||
<p>Modrinth Collection URL (Full):</p>
|
||||
<input type="text" id="url">
|
||||
<button onclick="set_url();">Set</button>
|
||||
<p>Server Type & Minecraft Version:</p>
|
||||
<select id="type">
|
||||
<option value="paper">Paper (default)</option>
|
||||
<option value="spigot">Spigot</option>
|
||||
<option value="fabric">Fabric</option>
|
||||
<option value="forge">Forge</option>
|
||||
<option value="velocity">Velocity</option>
|
||||
</select>
|
||||
|
||||
<select id="options"></select>
|
||||
<button onclick="get_plugins()" type="button" id="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<p>Log:</p>
|
||||
<div id="log" class="log" style="background-color: black"></div>
|
||||
|
||||
<div class="log_buttons">
|
||||
<button
|
||||
disabled
|
||||
id="btn_download_compatible"
|
||||
onclick="download_compatible()"
|
||||
>
|
||||
Install Compatible Plugins
|
||||
</button>
|
||||
<button disabled id="btn_download_all" onclick="download_all()">
|
||||
Install Compatible AND Incompatible Plugins (may cause issues)
|
||||
</button>
|
||||
<button disabled id="btn_download_zip" onclick="download_zip()">
|
||||
Download zip with no plugin folder changes (safest)
|
||||
</button>
|
||||
|
||||
<input type="file" id="plugins_folder" webkitdirectory multiple hidden />
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
//Call on every refresh
|
||||
rq_vers()
|
||||
url = get_url();
|
||||
get_path();
|
||||
|
||||
// vars
|
||||
let path_set = false;
|
||||
let url_set = false;
|
||||
let all_compatible_versions = [];
|
||||
let all_incompatible_versions = [];
|
||||
|
||||
|
||||
async function set_url() {
|
||||
const url = document.getElementById("url");
|
||||
|
||||
const response = await fetch("http://localhost:3000/api/seturl", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
body: url.value,
|
||||
});
|
||||
|
||||
for await (const text of response.body.pipeThrough(
|
||||
new TextDecoderStream(),
|
||||
)) {
|
||||
alert(text);
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function get_url() {
|
||||
const url = document.getElementById("url");
|
||||
const response = await fetch("http://localhost:3000/api/geturl", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.text();
|
||||
|
||||
if (data === "") {
|
||||
url.placeholder = "URL not set. URL must be set to continue."
|
||||
url_set = false;
|
||||
}
|
||||
|
||||
else {
|
||||
url.innerText = data;
|
||||
url.value = data;
|
||||
url_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function get_path() {
|
||||
const path = document.getElementById("path");
|
||||
const response = await fetch("http://localhost:3000/api/getpath", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.text();
|
||||
|
||||
if (data === "") {
|
||||
path.placeholder = "Path not set. Path must be set to continue."
|
||||
path_set = false;
|
||||
}
|
||||
|
||||
else {
|
||||
path.innerText = data;
|
||||
path.value = data;
|
||||
path_set = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async function set_path() {
|
||||
const path = document.getElementById("path");
|
||||
|
||||
const response = await fetch("http://localhost:3000/api/setpath", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
body: path.value,
|
||||
});
|
||||
|
||||
for await (const text of response.body.pipeThrough(
|
||||
new TextDecoderStream(),
|
||||
)) {
|
||||
alert(text);
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function rq_vers() {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onload = () => {
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
|
||||
const sel = document.getElementById("options");
|
||||
|
||||
for (let i = 0; i < data["versions"]["length"]; i++) {
|
||||
if (data["versions"][i]["type"] === "release") {
|
||||
var opt = document.createElement("option");
|
||||
opt.value = data["versions"][i]["id"];
|
||||
opt.innerHTML = data["versions"][i]["id"];
|
||||
sel.appendChild(opt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open(
|
||||
"GET",
|
||||
"https://piston-meta.mojang.com/mc/game/version_manifest_v2.json",
|
||||
);
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
|
||||
async function log_server_callback(array) {
|
||||
document.getElementById("btn_download_compatible").disabled = true;
|
||||
document.getElementById("btn_download_all").disabled = true;
|
||||
document.getElementById("btn_download_zip").disabled = true;
|
||||
const log = document.getElementById("log");
|
||||
|
||||
|
||||
const response = await fetch("http://localhost:3000/api/downloader/", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(array),
|
||||
});
|
||||
|
||||
for await (const chunk of response.body.pipeThrough(
|
||||
new TextDecoderStream(),
|
||||
)) {
|
||||
for (const line of chunk.split("\n")) {
|
||||
if (!line.trim()) continue;
|
||||
|
||||
log.insertAdjacentHTML("beforeend", `${line}<br>`);
|
||||
}
|
||||
|
||||
log.scrollTop = log.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
async function download_compatible() {
|
||||
log_server_callback(all_compatible_versions);
|
||||
all_compatible_versions = [];
|
||||
all_incompatible_versions = [];
|
||||
}
|
||||
|
||||
function download_all() {
|
||||
let combined = all_compatible_versions.concat(
|
||||
all_incompatible_versions,
|
||||
);
|
||||
log_server_callback(combined);
|
||||
all_compatible_versions = [];
|
||||
all_incompatible_versions = [];
|
||||
}
|
||||
|
||||
async function fetch_zip(array, file_name) {
|
||||
const response = await fetch("http://localhost:3000/api/downloader/direct", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(array),
|
||||
});
|
||||
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const a = document.createElement("a");
|
||||
|
||||
a.href = url;
|
||||
a.download = file_name;
|
||||
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function download_zip() {
|
||||
|
||||
document.getElementById("btn_download_compatible").disabled = true;
|
||||
document.getElementById("btn_download_all").disabled = true;
|
||||
document.getElementById("btn_download_zip").disabled = true;
|
||||
const log = document.getElementById("log");
|
||||
var lv = document.createElement("p");
|
||||
var lv2 = document.createElement("p");
|
||||
|
||||
lv.innerHTML = `Downloading Zips.. Please wait..`;
|
||||
lv.style.color = "white";
|
||||
lv.style.font = "Arial";
|
||||
log.appendChild(lv);
|
||||
|
||||
if (all_compatible_versions.length > 0) {
|
||||
await fetch_zip(all_compatible_versions, "compatible_versions.zip")
|
||||
}
|
||||
|
||||
if (all_incompatible_versions.length > 0) {
|
||||
await fetch_zip(all_incompatible_versions, "incompatible_versions.zip")
|
||||
}
|
||||
|
||||
all_compatible_versions = [];
|
||||
all_incompatible_versions = [];
|
||||
|
||||
lv2.innerHTML = `All downloads complete!`;
|
||||
lv2.style.color = "green";
|
||||
lv2.style.font = "Arial";
|
||||
log.appendChild(lv2);
|
||||
|
||||
}
|
||||
|
||||
async function get_plugins() {
|
||||
|
||||
if (path_set == false) {
|
||||
alert("Please set your plugin/mod folder before continuing.")
|
||||
return;
|
||||
}
|
||||
|
||||
if (url_set == false) {
|
||||
alert("Please set your Modrinth Collection URL before continuing.")
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const sel = document.getElementById("options");
|
||||
const log = document.getElementById("log");
|
||||
const submit = document.getElementById("submit");
|
||||
const type = document.getElementById("type");
|
||||
const url = document.getElementById("url");
|
||||
submit.disabled = true;
|
||||
document.getElementById("btn_download_compatible").disabled = true;
|
||||
document.getElementById("btn_download_all").disabled = true;
|
||||
document.getElementById("btn_download_zip").disabled = true;
|
||||
all_compatible_versions = [];
|
||||
all_incompatible_versions = [];
|
||||
compatible_mods_ids = [];
|
||||
incompatible_mods_ids = [];
|
||||
|
||||
log.innerHTML = "";
|
||||
const id = url.value.split("/").pop();
|
||||
|
||||
const response = await fetch(
|
||||
`http://localhost:3000/api/modrinth/collection/${id}`,
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.projects) {
|
||||
var not_found = document.createElement("p");
|
||||
|
||||
not_found.innerHTML = "The specified collection is empty or does not exist!";
|
||||
not_found.style.color = "#fc5d07";
|
||||
not_found.style.font = "Arial";
|
||||
|
||||
log.appendChild(not_found);
|
||||
|
||||
submit.disabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < data.projects["length"]; i++) {
|
||||
let id = data.projects[i];
|
||||
|
||||
const versions = await fetch(
|
||||
`https://api.modrinth.com/v2/project/${id}/version`,
|
||||
).then((r) => r.json());
|
||||
|
||||
const project = await fetch(
|
||||
`https://api.modrinth.com/v2/project/${id}`,
|
||||
).then((r) => r.json());
|
||||
|
||||
let latest = null;
|
||||
let latest_incompatible = null;
|
||||
|
||||
for (const version of versions) {
|
||||
if (!version.loaders.includes(type.value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (version.game_versions.includes(sel.value)) {
|
||||
if (latest === null ||new Date(version.date_published) > new Date(latest.date_published)) {
|
||||
latest = version;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
if (latest_incompatible === null || new Date(version.date_published) > new Date(latest_incompatible.date_published)
|
||||
) {
|
||||
latest_incompatible = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var lv = document.createElement("p");
|
||||
|
||||
var project_link = `https://modrinth.com/plugin/${project.slug}`;
|
||||
|
||||
if (latest) {
|
||||
lv.innerHTML = `Found matching version with name: ${latest["name"]}, <a href="${project_link}" target="_blank">link: ${project_link}</a>`;
|
||||
lv.style.color = "green";
|
||||
lv.style.font = "Arial";
|
||||
all_compatible_versions.push(latest.id);
|
||||
log.appendChild(lv);
|
||||
} else if (latest_incompatible) {
|
||||
lv.innerHTML = `No compatible version found for ${id}, name: ${project.title}, <a href="${project_link}" target="_blank">link: ${project_link}</a>`;
|
||||
lv.style.color = "#fc5d07";
|
||||
lv.style.font = "Arial";
|
||||
all_incompatible_versions.push(latest_incompatible.id);
|
||||
|
||||
log.appendChild(lv);
|
||||
} else {
|
||||
lv.innerHTML = `Mod/Plugin ${project.title} does not have an option for the selected loader`
|
||||
lv.style.color = "#fc5d07";
|
||||
lv.style.font = "Arial";
|
||||
log.appendChild(lv);
|
||||
|
||||
}
|
||||
|
||||
if (!versions.length) {
|
||||
console.warn(`No versions found for ${project.id}`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
submit.disabled = false;
|
||||
|
||||
if (all_compatible_versions.length > 0 || all_incompatible_versions > 0) {
|
||||
document.getElementById("btn_download_compatible").disabled = false;
|
||||
document.getElementById("btn_download_all").disabled = false;
|
||||
document.getElementById("btn_download_zip").disabled = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
a {
|
||||
color: #c4c9ce;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #c4c9ce;
|
||||
}
|
||||
|
||||
.log {
|
||||
width: 100%;
|
||||
height: 350px;
|
||||
color: white;
|
||||
overflow: scroll;
|
||||
}
|
||||
|
||||
.log_buttons {
|
||||
margin-top: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.log_buttons button:disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user