Fix download

This commit is contained in:
2026-10-07 16:31:47 -03:00
parent 6fe5e0809e
commit 7767efab58
3 changed files with 13 additions and 4 deletions
+3 -3
View File
@@ -244,12 +244,12 @@ function has_singleplayer() {
return new URL(location.href).searchParams.has("singleplayer");
}
// the desktop app's build for the os the browser is on, next to the page in dist/. everything that isn't windows
// the desktop app's build for the os the browser is on, which the server has in /dist/, see DESKTOP_DOWNLOADS. everything that isn't windows
// gets linux's
function download_os() {
return /windows/i.test(navigator.userAgent)
? { name: "Windows", file: "dist/windows.zip" }
: { name: "Linux", file: "dist/linux.zip" };
? { name: "Windows", file: "/dist/windows.zip" }
: { name: "Linux", file: "/dist/linux.zip" };
}
function download_desktop_app() {
+9 -1
View File
@@ -1,6 +1,6 @@
// the part of a game server that has permissions: files and networking. the game itself runs in a worker with none.
// server/main.ts runs it as a dedicated server, and the desktop app runs it for singleplayer
import { serveDir } from "@std/http/file-server";
import { serveDir, serveFile } from "@std/http/file-server";
import { join } from "@std/path";
import { GameToHost, HostToGame } from "./game/host_protocol.ts";
import { load_bmods } from "./load_bmods.ts";
@@ -12,12 +12,16 @@ const MAX_MESSAGE_SIZE = 4096;
export const ENGINE_TEXTURES_INDEX = "assets/textures/index.json";
const SHUTDOWN_TIMEOUT_MS = 5000;
const DOWNLOAD_TIMEOUT_MS = 10_000;
// the desktop app's zips that deno task desktop-all makes, for the title screen's download button
export const DESKTOP_DOWNLOADS = ["windows.zip", "linux.zip"];
export interface HostOptions {
// what deno task build made: the client and the engine's assets
build_dir: string;
// the .bmod files to load
server_mods_dir: string;
// where DESKTOP_DOWNLOADS are, served at /dist/. without it there's nothing to download
dist_dir?: string;
// the world's folder: level.json, and the blocks in region/
world_dir: string;
seed?: string;
@@ -170,6 +174,10 @@ export async function start_host(options: HostOptions): Promise<Host> {
},
});
}
const desktop_download = url.pathname.match(/^\/dist\/([^/]+)$/)?.[1];
if (options.dist_dir && desktop_download && DESKTOP_DOWNLOADS.includes(desktop_download)) {
return serveFile(req, join(options.dist_dir, desktop_download));
}
return serve_static(options.build_dir, req, url);
},
+1
View File
@@ -8,6 +8,7 @@ try {
host = await start_host({
build_dir: Deno.env.get("BUILD_DIR") ?? "build",
server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods",
dist_dir: Deno.env.get("DIST_DIR") ?? "dist",
world_dir: Deno.env.get("WORLD_DIR") ?? "world",
seed: Deno.env.get("SEED"),
on_fatal(message) {