mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
+99
-1
@@ -59,6 +59,8 @@ const flashVars = () => ({
|
||||
deploy_version: config.deployVersion,
|
||||
// for the custom client: are its advanced login settings honoured here?
|
||||
loginChoices: config.loginChoices,
|
||||
// member or not may be chosen on any server (lib/accounts.js)
|
||||
membershipChoice: true,
|
||||
smoke_version: config.deployVersion,
|
||||
clientURL: `${config.baseUrl}${config.deployVersion}/ajclient.swf?v=${config.buildVersion}`,
|
||||
startupRoom: config.startupRoom,
|
||||
@@ -170,7 +172,42 @@ const keepClientError = text => {
|
||||
const THEMED_ROOM = /^(\d+)\/roomDefs\/theme_(\d+)\/(.+)$/;
|
||||
|
||||
// the web pages, as against what the game and the client load
|
||||
const SITE_PAGES = /^\/(?:register|terms|privacy|commands|shop|account|mod)?\/?$/;
|
||||
const SITE_PAGES = /^\/(?:register|terms|privacy|commands|shop|account|mod|download)?\/?$/;
|
||||
|
||||
// the installers /download offers, those of them config.downloadsDir has
|
||||
const DOWNLOADS = [
|
||||
{file: "Burrow-Setup.exe", system: "Windows", detail: "SmartScreen may warn you about this file. Click 'More info', then 'Run anyway'."},
|
||||
// shown as coming until there is one
|
||||
{file: "Burrow-macos.dmg", system: "macOS", detail: "The first time: right-click Burrow, then Open", soon: true},
|
||||
{file: "Burrow-x86_64.AppImage", system: "Linux", detail: "AppImage, for any distribution"},
|
||||
{file: "burrow_amd64.deb", system: "Debian, Ubuntu, Mint", detail: ".deb"},
|
||||
{file: "burrow.x86_64.rpm", system: "Fedora, openSUSE", detail: ".rpm"},
|
||||
];
|
||||
const DOWNLOAD_PATH = /^\/download\/(Burrow-Setup\.exe|Burrow-macos\.dmg|Burrow-x86_64\.AppImage|burrow_amd64\.deb|burrow\.x86_64\.rpm|SHA256SUMS)$/;
|
||||
// a file's address carries this, so that a new upload is a new address that
|
||||
// no cache (cloudflare keeps such files for hours) answers with the old one
|
||||
const fileVersion = stat => `${stat.size.toString(36)}${Math.floor(stat.mtimeMs).toString(36)}`;
|
||||
const statOf = file => fs.promises.stat(path.join(config.downloadsDir, file)).catch(() => null);
|
||||
// what each installer is: RELEASES beside them, written by the client's
|
||||
// build, a line each: "Burrow-Setup.exe 1.1.0 2026-10-14". a file it does
|
||||
// not name shows the day it was put there.
|
||||
const releasesOf = async () => {
|
||||
const text = await fs.promises.readFile(path.join(config.downloadsDir, "RELEASES"), "utf8").catch(() => "");
|
||||
const releases = {};
|
||||
for (const line of text.split("\n")) {
|
||||
const [file, version, date] = line.trim().split(/\s+/);
|
||||
if (file) {
|
||||
releases[file] = {version, date};
|
||||
}
|
||||
}
|
||||
return releases;
|
||||
};
|
||||
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
const releaseLine = (release, stat) => {
|
||||
const version = release && /^\d{1,5}\.\d{1,5}\.\d{1,5}$/.test(release.version) ? `Version ${release.version}` : "";
|
||||
const day = release && /^\d{4}-\d{2}-\d{2}$/.test(release.date) ? new Date(`${release.date}T12:00:00Z`) : stat.mtime;
|
||||
return [version, `${day.getUTCDate()} ${MONTHS[day.getUTCMonth()]} ${day.getUTCFullYear()}`].filter(Boolean).join(" · ");
|
||||
};
|
||||
|
||||
// origins a client's own page has: a file, as browsers name it.
|
||||
const CLIENT_ORIGINS = ["null", "file://"];
|
||||
@@ -210,6 +247,58 @@ const sendHomePage = async res => {
|
||||
.replace(/\{\{(\w+)\}\}/g, (whole, name) => (Object.hasOwn(HOME_VALUES, name) ? escapeHtml(HOME_VALUES[name]) : whole));
|
||||
send(res, 200, page, MIME[".html"]);
|
||||
};
|
||||
const sendDownloadPage = async res => {
|
||||
for (const [name, value] of Object.entries(PAGE_HEADERS)) {
|
||||
res.setHeader(name, value);
|
||||
}
|
||||
const rows = [];
|
||||
const releases = await releasesOf();
|
||||
for (const entry of DOWNLOADS) {
|
||||
const stat = await statOf(entry.file);
|
||||
if (stat && stat.isFile()) {
|
||||
rows.push(`<div class="row"><div><div class="system">${escapeHtml(entry.system)}</div>`
|
||||
+ `<div class="detail">${escapeHtml(entry.detail)}</div>`
|
||||
+ `<div class="detail">${escapeHtml(releaseLine(releases[entry.file], stat))} · ${Math.round(stat.size / 1048576)} MB</div></div>`
|
||||
+ `<a class="get" href="/download/${entry.file}?v=${fileVersion(stat)}" download>Download</a></div>`);
|
||||
}
|
||||
else if (entry.soon) {
|
||||
rows.push(`<div class="row"><div><div class="system">${escapeHtml(entry.system)}</div></div><span class="soon">Soon</span></div>`);
|
||||
}
|
||||
}
|
||||
const sums = await statOf("SHA256SUMS");
|
||||
const values = {
|
||||
rows: rows.length ? rows.join("\n ") : '<p class="none">Coming soon.</p>',
|
||||
sums: sums ? `<a href="/download/SHA256SUMS?v=${fileVersion(sums)}">Checksums</a>` : "",
|
||||
};
|
||||
const page = (await fs.promises.readFile(path.join(config.publicDir, "download.html"), "utf8"))
|
||||
.replace(/\{\{(\w+)\}\}/g, (whole, name) => (Object.hasOwn(values, name) ? values[name] : whole));
|
||||
send(res, 200, page, MIME[".html"]);
|
||||
};
|
||||
|
||||
// one installer, read from disk as it goes out: they are tens of MB.
|
||||
const sendDownload = async (req, res, file) => {
|
||||
const full = path.join(config.downloadsDir, file);
|
||||
const stat = await statOf(file);
|
||||
if (!stat || !stat.isFile()) {
|
||||
send(res, 404, "Not found", "text/plain");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
"Content-Type": file === "SHA256SUMS" ? "text/plain; charset=utf-8" : "application/octet-stream",
|
||||
"Content-Length": stat.size,
|
||||
"Content-Disposition": file === "SHA256SUMS" ? "inline" : `attachment; filename="${file}"`,
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
});
|
||||
if (req.method === "HEAD") {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
const stream = fs.createReadStream(full);
|
||||
stream.on("error", () => res.destroy());
|
||||
res.on("close", () => stream.destroy());
|
||||
stream.pipe(res);
|
||||
};
|
||||
|
||||
const sendPage = async (res, file, headers = PAGE_HEADERS) => {
|
||||
for (const [name, value] of Object.entries(headers)) {
|
||||
res.setHeader(name, value);
|
||||
@@ -512,6 +601,12 @@ const handle = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const download = (req.method === "GET" || req.method === "HEAD") && DOWNLOAD_PATH.exec(url.pathname);
|
||||
if (download) {
|
||||
await sendDownload(req, res, download[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
// the badges and the Discord mark on player cards (public/badges/, lib/badges.js).
|
||||
const badgeArt = req.method === "GET" && /^\/badges\/([a-z0-9]{1,30}\.png)$/.exec(url.pathname);
|
||||
if (badgeArt) {
|
||||
@@ -522,6 +617,9 @@ const handle = async (req, res) => {
|
||||
}
|
||||
|
||||
switch (route) {
|
||||
case "GET /download":
|
||||
await sendDownloadPage(res);
|
||||
return;
|
||||
case "GET /register":
|
||||
await sendPage(res, "register.html", CAPTCHA_PAGE_HEADERS);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user