feat: bulletproof updater + fixes for client links (icons/furniture/gamedata)
CI / check (push) Failing after 8s
CI / release (push) Skipped
CI / deploy (push) Skipped

This commit is contained in:
openhands committed 2026-08-30 18:19:46 +02:00
1 parent f2ac4745d4
commit 678d22ceab
3 files changed
+346 -74

No files matched your search

+34 -5
View File
@@ -13,9 +13,10 @@
// NITRO_IMAGE_LIBRARY_URL, NITRO_HOF_FURNITURE_URL, NITRO_API_URL,
// NITRO_SOCKET_URL, NITRO_GAMEDATA_URL, NITRO_ASSET_URL,
// NITRO_FURNI_ASSET_ICON_URL
// NITRO_URL_FORCE=1 (optional) overwrite existing values too
const fs = require("node:fs");
const path = require("node:path");
const { parse, modify } = require("jsonc-parser");
const { parse } = require("jsonc-parser");
const FILES = [
"renderer-config.json",
@@ -23,6 +24,22 @@ const FILES = [
"ui-config.json",
];
const FORCE = process.env.NITRO_URL_FORCE === "1";
// Values that must never survive into a production config: placeholder or
// loopback hosts that originate from the upstream example files. When a key
// still holds one of these, it has been newly added by the merge step and has
// to be filled from the environment. A real, already-configured URL (the
// hotel's own domain) is NEVER rewritten, so hotel links stay exactly as the
// hotel owner configured them.
const PLACEHOLDER_RE =
/(localhost|127\.0\.0\.1|0\.0\.0\.0|::1|\.example\.com|nitro\.example\.|hotel\.example\.|example\.org|example\.net|:5173|:2096|\$\{)/i;
function isPlaceholder(value) {
if (!value) return true;
return PLACEHOLDER_RE.test(value);
}
function env(name) {
return process.env[name]?.length ? process.env[name] : null;
}
@@ -36,9 +53,14 @@ function applyOverrides(data) {
const asset = env("NITRO_ASSET_URL");
const icon = env("NITRO_FURNI_ASSET_ICON_URL");
// Add-only, placeholder-aware URL fill-in. Existing real values are kept,
// crypto.* keys are never touched, and only missing/placeholder keys are
// filled from the environment. NITRO_URL_FORCE=1 opts back into overwriting.
const set = (key, value) => {
if (value && !(key in data)) data[key] = value;
if (value) data[key] = value;
if (!value || key.startsWith("crypto.")) return;
if (FORCE || !(key in data) || isPlaceholder(data[key])) {
data[key] = value;
}
};
set("image.library.url", image);
@@ -49,12 +71,19 @@ function applyOverrides(data) {
set("asset.url", asset);
set("furni.asset.icon.url", icon);
if (gamedata) {
if (gamedata && (!("radio.url" in data) || isPlaceholder(data["radio.url"]))) {
data["radio.url"] = `${gamedata}/config/radio-stations.jsonc?t=%timestamp%`;
}
if (
gamedata &&
(!("soundboard.url" in data) || isPlaceholder(data["soundboard.url"]))
) {
data["soundboard.url"] =
`${gamedata}/config/soundboard-sounds.jsonc?t=%timestamp%`;
}
if ("show.google.ads" in data) data["show.google.ads"] = false;
// Never force ads on/off over a hotel's own choice; only default to "off"
// when the key does not exist yet (prevents external ad scripts from 404ing).
if (!("show.google.ads" in data)) data["show.google.ads"] = false;
return data;
}