fix: 版本更新 — 自动检查 + 手动备份 + 创建备份按钮

1. 设置页加载时自动触发版本检查
2. POST /api/updates/backup — 手动创建备份
3. 备份管理区新增「+ 创建备份」按钮
4. 顶栏版本按钮: checkTopUpdate 每10min轮询

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
qinglong
2026-06-13 21:08:54 +08:00
parent 95a2f375e8
commit 67d0f00525
2 changed files with 40 additions and 2 deletions
+28
View File
@@ -43,6 +43,7 @@ def setup_routes(app, prefix=''):
app.router.add_get(f'{prefix}/api/updates', panel_auth(get_updates))
app.router.add_post(f'{prefix}/api/updates/check', panel_auth(check_now))
app.router.add_post(f'{prefix}/api/updates/apply', panel_auth(apply_update))
app.router.add_post(f'{prefix}/api/updates/backup', panel_auth(create_backup))
app.router.add_get(f'{prefix}/api/updates/backups', panel_auth(list_backups))
app.router.add_post(f'{prefix}/api/updates/rollback', panel_auth(do_rollback))
logger.info(f"📡 系统状态WS端点已注册: {prefix}/api/system/ws (已加认证)")
@@ -180,6 +181,33 @@ async def list_backups(req):
return web.json_response({"backups": backups})
async def create_backup(req):
"""手动创建备份"""
import time as _time, os as _os
from services.update_service import _backup_current, _PROJECT_ROOT
backup_dir = _os.path.join(_PROJECT_ROOT, "data", "backups")
_os.makedirs(backup_dir, exist_ok=True)
try:
sm = req.app.get("service_manager")
ver = "unknown"
if sm:
try:
init = sm.get_service("init")
ver = init.get_config("base").get("framework", {}).get("version", "0.0.0")
except: pass
name = f"SenSu_backup_{ver}_{_time.strftime('%Y%m%d_%H%M%S')}.zip"
dest = _os.path.join(backup_dir, name)
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, _backup_current, dest)
# 清理旧备份
backups = sorted(glob.glob(_os.path.join(backup_dir, "SenSu_backup_*.zip")), key=_os.path.getmtime, reverse=True)
for old_b in backups[5:]:
_os.unlink(old_b)
return web.json_response({"ok": True, "name": name})
except Exception as e:
return web.json_response({"ok": False, "error": str(e)}, status=500)
async def do_rollback(req):
"""执行回滚"""
import glob, os, zipfile, shutil, tempfile