fix: 解决自动更新无限重启循环 + 终点站列车不显示在预测列表
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
This commit is contained in:
+24
-3
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user