mcbe-portal
Version:
Connect bedrock servers together using mcbe-portal, manage your servers with ease.
40 lines (32 loc) • 1.48 kB
JavaScript
const https = require("node:https");
async function latesetURL(sys = "linux", preview = false) {
const config = {
url: "https://www.minecraft.net/en-us/download/server/bedrock",
agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
}
return new Promise((resolve, reject) => {
https.get(config.url, { headers: { "User-Agent": config.agent } }, (res) => {
let data = "";
res.on("data", chunk => data += chunk);
res.on("end", () => {
const regex = /https:\/\/www\.minecraft\.net\/bedrockdedicatedserver\/bin-[^"]+/g;
const matches = data.match(regex);
if (!matches) return reject("No URLs found");
const dict = {};
for (const link of matches) {
if (link.includes("bin-win-preview/")) dict["win-preview"] = link;
else if (link.includes("bin-linux-preview/")) dict["linux-preview"] = link;
else if (link.includes("bin-win/")) dict["win"] = link;
else if (link.includes("bin-linux/")) dict["linux"] = link;
}
const key = preview ? `${sys}-preview` : sys;
resolve(dict[key]);
});
}).on("error", reject);
});
}
const OSMap = {
win32: 'win',
linux: 'linux'
};
module.exports = { latesetURL, OSMap }