diff --git a/gate.lua b/gate.lua index 9de49e2..deb7efa 100644 --- a/gate.lua +++ b/gate.lua @@ -89,10 +89,9 @@ local speaker = peripheral.find("speaker") local inspection = peripheral.find("ticket_inspection_machine") local serverConnected = nil -local serverLastChangeTs = 0 -local expectedGateVersion = nil local versionMismatch = nil local pendingGateUpdate = false +local remoteForceUpdate = false local isUpdating = false local gateBusyUntilTs = 0 @@ -395,6 +394,7 @@ local function refreshRemoteLuaVersion(serverBase) local ok, parsed = getJSON(url) if not ok or type(parsed) ~= "table" then return false end local remote = normalizeVersionTag(type(parsed.lua_versions) == "table" and parsed.lua_versions.gate or nil) + remoteForceUpdate = (parsed.force_update == true) if #remote == 0 then expectedGateVersion = nil versionMismatch = nil @@ -1427,7 +1427,7 @@ while true do pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) - if type(cfg) == "table" and type(cfg.force_update) == "boolean" and cfg.force_update == true and versionMismatch == true then + if remoteForceUpdate and versionMismatch == true then pendingGateUpdate = true end diff --git a/server/routes/api.js b/server/routes/api.js index dae9567..1c8a25d 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -162,7 +162,8 @@ router.get('/config', (req, res) => { fares: DataService.getFares(), transfers: cfg.transfers || [], promotion: cfg.promotion || { name: '', discount: 1 }, - lua_versions: cfg.lua_versions || {} + lua_versions: cfg.lua_versions || {}, + force_update: cfg.force_update === true }); }); @@ -185,6 +186,9 @@ router.put('/config', async (req, res) => { ...(incoming.lua_versions || {}) }; } + if (typeof incoming.force_update === 'boolean') { + cfg.force_update = incoming.force_update; + } await DataService.saveConfig(cfg); appendReqLog(req, { category: 'admin', type: 'update_config_generic', detail: incoming }); io.emit('config:updated', cfg); diff --git a/server/routes/public.js b/server/routes/public.js index ec2457a..5e2b759 100644 --- a/server/routes/public.js +++ b/server/routes/public.js @@ -228,7 +228,8 @@ router.get('/config', (req, res) => { const cfg = DataService.getConfig(); res.json({ promotion: { name: cfg.promotion?.name || '', discount: cfg.promotion?.discount ?? 1 }, - lua_versions: cfg.lua_versions || {} + lua_versions: cfg.lua_versions || {}, + force_update: cfg.force_update === true }); }); diff --git a/ticketmachine.lua b/ticketmachine.lua index 298805f..b7bf5ac 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -681,7 +681,7 @@ local function backgroundSyncTask() sleep(UPDATE_CHECK_INTERVAL) pcall(refreshConfigOnce) - if type(cfg) == 'table' and type(cfg.force_update) == 'boolean' and cfg.force_update == true and versionMismatch == true then + if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then pendingMachineUpdate = true end end diff --git a/web/index.html b/web/index.html index f61d163..4c5b4fe 100644 --- a/web/index.html +++ b/web/index.html @@ -815,14 +815,10 @@