feat: add warning card for db key

This commit is contained in:
H3CoF6
2026-02-09 00:59:13 +08:00
parent d13e1dcfc6
commit b766e051ed
6 changed files with 103 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ from typing import Optional
from fastapi import APIRouter
from ..key_store import get_account_keys_from_store
from ..key_service import get_db_key_workflow
from ..media_helpers import _load_media_keys, _resolve_account_dir
from ..path_fix import PathFixRoute

View File

@@ -1,5 +1,5 @@
from typing import Optional
import psutil
from fastapi import APIRouter
from ..logging_config import get_logger
@@ -71,3 +71,49 @@ async def detect_current_account(data_root_path: Optional[str] = None):
'error': str(e),
'data': None,
}
@router.get("/api/wechat/status", summary="检查微信运行状态")
async def check_wechat_status():
"""
检查系统中是否有 Weixin.exe 或 WeChat.exe 进程在运行
返回: status=0 成功, wx_status={is_running: bool, pid: int, ...}
"""
process_name_targets = ["Weixin.exe", "WeChat.exe"]
wx_status = {
"is_running": False,
"pid": None,
"exe_path": None,
"memory_usage_mb": 0.0
}
try:
for proc in psutil.process_iter(['pid', 'name', 'exe', 'memory_info']):
try:
if proc.info['name'] and proc.info['name'] in process_name_targets:
wx_status["is_running"] = True
wx_status["pid"] = proc.info['pid']
wx_status["exe_path"] = proc.info['exe']
mem = proc.info['memory_info']
if mem:
wx_status["memory_usage_mb"] = round(mem.rss / (1024 * 1024), 2)
break
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
return {
"status": 0,
"errmsg": "ok",
"wx_status": wx_status
}
except Exception as e:
# 即使出错也返回 JSON但 status 非 0
return {
"status": -1,
"errmsg": f"检查进程失败: {str(e)}",
"wx_status": wx_status
}