feat: 在后端增加解析远程 Gitea 最新版本号的接口并展示在前端
This commit is contained in:
@@ -1711,8 +1711,11 @@
|
||||
const localVersion = info?.localVersion || '未知';
|
||||
const targetVersion = info?.targetVersion || '未发布';
|
||||
const publishedAt = info?.publishedAt ? new Date(info.publishedAt).toLocaleString() : '未发布';
|
||||
const remoteVersionHtml = info?.remoteVersion ? `<div>Gitea最新:${info.remoteVersion}</div>` : '';
|
||||
|
||||
el.innerHTML = `
|
||||
<div>服务器脚本:${localVersion}</div>
|
||||
${remoteVersionHtml}
|
||||
<div>已发布版本:${targetVersion}</div>
|
||||
<div style="margin-top:4px;color:var(--text-muted)">发布时间:${publishedAt}</div>
|
||||
`;
|
||||
@@ -1723,6 +1726,19 @@
|
||||
const res = await fetch('/api/station-update');
|
||||
const data = await res.json();
|
||||
currentStationUpdate = data;
|
||||
|
||||
try {
|
||||
const remoteRes = await fetch('/api/remote-version');
|
||||
const remoteData = await remoteRes.json();
|
||||
if (remoteData.success) {
|
||||
data.remoteVersion = remoteData.version;
|
||||
} else {
|
||||
data.remoteVersion = '解析失败';
|
||||
}
|
||||
} catch (e) {
|
||||
data.remoteVersion = '请求失败';
|
||||
}
|
||||
|
||||
renderStationUpdate(data);
|
||||
} catch (e) {
|
||||
document.getElementById('current-version').textContent = 'Error';
|
||||
|
||||
@@ -2372,6 +2372,23 @@ function convertToDfpwm(filePath) {
|
||||
}
|
||||
|
||||
// Routes
|
||||
app.get('/api/remote-version', async (req, res) => {
|
||||
try {
|
||||
const response = await fetch('https://gitea.fse-media.group/Henry_Du/CC-StationBroadcast/raw/branch/main/station_broadcast.lua');
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const text = await response.text();
|
||||
const match = text.match(/local\s+APP_VERSION_TEXT\s*=\s*["']([^"']+)["']/);
|
||||
if (match) {
|
||||
res.json({ success: true, version: String(match[1]).trim() });
|
||||
} else {
|
||||
res.json({ success: false, message: 'Version match failed' });
|
||||
}
|
||||
} catch (e) {
|
||||
log('ERROR', `Failed to fetch remote version: ${e.message}`);
|
||||
res.status(500).json({ success: false, message: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/version', (req, res) => {
|
||||
res.json({ version: audioVersion });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user