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 @@
-
- -
-
-
推送中... {{ updateProgress }}%
-
-
-
+
+
点击按钮后,将向全服所有终端发送更新指令,并在 5 秒内生效。
终端将在业务空闲时静默下载更新并重启,未加载的机器在加载后也会第一时间更新。 diff --git a/web/index.js b/web/index.js index 76c47dd..9283253 100644 --- a/web/index.js +++ b/web/index.js @@ -1477,13 +1477,11 @@ createApp({ }; const isPushingUpdate = ref(false); - const updateProgress = ref(0); const pushLuaUpdate = async () => { if (!confirm('确定要向所有机器推送更新指令吗?这将会使空闲机器静默更新并重启。')) return; isPushingUpdate.value = true; - updateProgress.value = 0; // 自动提升版本号 & 开启 force_update if (!config.lua_versions.ticketmachine) config.lua_versions.ticketmachine = 'v1.0.0'; @@ -1494,20 +1492,12 @@ createApp({ try { await requestJson('/api/config', { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(config) }, { expectOk: true }); - - // 模拟进度条,持续约 5 秒 (设备5秒轮询一次) - for (let i = 0; i <= 100; i += 2) { - updateProgress.value = i; - await new Promise(resolve => setTimeout(resolve, 100)); // 100ms * 50 = 5000ms - } - toast('推送指令发送完毕,终端将陆续更新', 'success'); } catch (err) { console.error(err); toast('推送更新失败', 'error'); } finally { isPushingUpdate.value = false; - updateProgress.value = 100; } }; @@ -1762,7 +1752,7 @@ createApp({ saveCurrentFare, deleteCurrentFare, closeFareModal, - saveConfig, isPushingUpdate, updateProgress, pushLuaUpdate, exportData, exportFareMap, + saveConfig, isPushingUpdate, pushLuaUpdate, exportData, exportFareMap, formatTime, formatLogDetail, getStationName, getStationInfo, loadFareMap, fetchData, refreshData: fetchData, fareMapScale, fareMapLoading, fareMapError, zoomFareMapIn, zoomFareMapOut, zoomFareMapReset, isTransferStation, getTransferTitleSuffix, getTransferLineBadges