From 34d9ed00d6574c592737ca72bebd97980cbf9383 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 16 Aug 2026 12:32:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A0=E9=99=90=E9=87=8D=E5=90=AF=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=20+=20=E7=BB=88=E7=82=B9=E7=AB=99=E5=88=97=E8=BD=A6?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=9C=A8=E9=A2=84=E6=B5=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. CloudServer: publishStationUpdate 发布时同步 Gitea 最新脚本到本地副本 - 新增 fetchGiteaScript() 一次下载全文 - 发布更新时将 Gitea 脚本内容写入 stationScriptPath - 保证 targetVersion 与 /downloads/station_broadcast.lua 内容版本一致 2. 客户端 AutoUpdate.apply: 下载后校验版本一致性 - 从下载内容正则提取 APP_VERSION_TEXT - 若 downloadedVersion ~= targetVersion 则中止更新,防止 reboot loop - 写入错误日志便于排查 3. 预测显示: 在站列车(尤其终点站)强制插入 upcomingTrains 列表头部 - CRN 可能从 TrainStops 提前移除终点站列车 - 使用 normalizeUpcomingKey 去重避免重复条目 - 固定 ETA=0,确保 CURREN T TRAIN 对应列车能在 UPCOMING 中可见 版本号 v1.0.68 -> v1.0.69 --- CloudServer/server.js | 27 ++++++++++++++++++++++++--- station_broadcast.lua | 12 ++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CloudServer/server.js b/CloudServer/server.js index 2cf440f..efc4936 100644 --- a/CloudServer/server.js +++ b/CloudServer/server.js @@ -259,11 +259,20 @@ function maybeSendStationUpdate(ws, stationName, stationVersion) { } } -async function fetchGiteaVersion() { +async function fetchGiteaScript() { try { const response = await fetch('https://gitea.fse-media.group/Henry_Du/CC-StationBroadcast/raw/branch/main/station_broadcast.lua'); if (!response.ok) return null; - const text = await response.text(); + return await response.text(); + } catch (e) { + return null; + } +} + +async function fetchGiteaVersion() { + try { + const text = await fetchGiteaScript(); + if (!text) return null; const match = text.match(/local\s+APP_VERSION_TEXT\s*=\s*["']([^"']+)["']/); return match ? String(match[1]).trim() : null; } catch (e) { @@ -272,10 +281,22 @@ async function fetchGiteaVersion() { } async function publishStationUpdate(req) { - let version = await fetchGiteaVersion(); + let version = null; + let giteaText = await fetchGiteaScript(); + if (giteaText) { + const match = giteaText.match(/local\s+APP_VERSION_TEXT\s*=\s*["']([^"']+)["']/); + version = match ? String(match[1]).trim() : null; + } if (!version) { version = getLocalStationScriptVersion() || `build-${Date.now()}`; log('WARN', `Failed to fetch Gitea version, falling back to local version: ${version}`); + } else if (giteaText) { + try { + fs.writeFileSync(stationScriptPath, giteaText, 'utf8'); + log('INFO', `Synced station_broadcast.lua from Gitea to local (version ${version})`); + } catch (e) { + log('ERROR', `Failed to sync station_broadcast.lua to local: ${e.message}`); + } } const releaseId = String(Date.now()); diff --git a/station_broadcast.lua b/station_broadcast.lua index c9bcb76..d52a197 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2231,6 +2231,18 @@ function AutoUpdate.apply(info, reason) return false, err end + local downloadedVersion = nil + do + local m = string.match(body, 'local%s+APP_VERSION_TEXT%s*=%s*["\']([^"\']+)["\']') + if m then downloadedVersion = Utils.trim(m) end + end + + if downloadedVersion and downloadedVersion ~= targetVersion then + State.updateInProgress = false + Utils.log("ERROR", "Downloaded version mismatch: target=" .. tostring(targetVersion) .. " got=" .. tostring(downloadedVersion) .. " - aborting update to prevent reboot loop") + return false, "downloaded version mismatch (" .. tostring(downloadedVersion) .. " ~= " .. tostring(targetVersion) .. ")" + end + local ok, writeErr = AutoUpdate.writeFile(startupPath, body) if not ok then State.updateInProgress = false