From 8a78034ad384725aed2c06b09e448ba9d4a00306 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 23:38:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0Lua=E8=84=9A=E6=9C=AC=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=B9=B6=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增配置API的force_update字段返回与保存支持,更新终端Lua脚本逻辑以支持强制更新标记,同时简化前端更新按钮,移除模拟进度条并动态切换按钮状态与显示文本。 --- gate.lua | 6 +++--- server/routes/api.js | 6 +++++- server/routes/public.js | 3 ++- ticketmachine.lua | 2 +- web/index.html | 12 ++++-------- web/index.js | 12 +----------- 6 files changed, 16 insertions(+), 25 deletions(-) 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 @@