feat: 发布更新时优先使用远程 Gitea 仓库的版本号
This commit is contained in:
+21
-4
@@ -259,8 +259,25 @@ function maybeSendStationUpdate(ws, stationName, stationVersion) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishStationUpdate(req) {
|
async function fetchGiteaVersion() {
|
||||||
const version = getLocalStationScriptVersion() || `build-${Date.now()}`;
|
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();
|
||||||
|
const match = text.match(/local\s+APP_VERSION_TEXT\s*=\s*["']([^"']+)["']/);
|
||||||
|
return match ? String(match[1]).trim() : null;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function publishStationUpdate(req) {
|
||||||
|
let version = await fetchGiteaVersion();
|
||||||
|
if (!version) {
|
||||||
|
version = getLocalStationScriptVersion() || `build-${Date.now()}`;
|
||||||
|
log('WARN', `Failed to fetch Gitea version, falling back to local version: ${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
const releaseId = String(Date.now());
|
const releaseId = String(Date.now());
|
||||||
stationUpdate = {
|
stationUpdate = {
|
||||||
version,
|
version,
|
||||||
@@ -2400,8 +2417,8 @@ app.get('/api/station-update', (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/station-updates/publish', (req, res) => {
|
app.post('/api/station-updates/publish', async (req, res) => {
|
||||||
const result = publishStationUpdate(req);
|
const result = await publishStationUpdate(req);
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
...result
|
...result
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
local APP_VERSION_TEXT = "v1.0.65"
|
local APP_VERSION_TEXT = "v1.0.66"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
|
|||||||
Reference in New Issue
Block a user