站点配置(百世密码/韵达账密/安能路径)从 config.yaml 移至 state.db
- state_store:加 site_settings(site,key,value) 表 + get_setting/set_setting/get_site_settings
- runtime:seed_legacy_config 启动一次性从 config.yaml 灌入(已存在不覆盖);安能 app_path 改读 state_store
- site_baishi:导出密码改读 get_setting("百世","password")
- site_yunda:登录账密改读 get_setting("韵达",...)
- server:/config PUT 接受 settings;新增 GET /config/{site}/settings(不进 5s 轮询)
debug 仍保留在 config.yaml;站点配置现由前端配置弹窗管理(state.db 为准)。
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
40
runtime.py
40
runtime.py
@@ -206,24 +206,44 @@ class RuntimeContext:
|
||||
# ============================ 启动 + 就绪 + 弹窗 ============================
|
||||
|
||||
|
||||
def seed_legacy_config():
|
||||
"""一次性:把 config.yaml 里的站点配置(百世密码 / 韵达账密 / 安能 exe 路径)
|
||||
灌入 state.db。已存在的值不覆盖(前端改过的不动)。"""
|
||||
if not os.path.exists(CONFIG_PATH):
|
||||
return
|
||||
try:
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
cfg = yaml.safe_load(f) or {}
|
||||
except Exception as e:
|
||||
print(f"⚠️ 读取 config.yaml 做 seed 失败: {e}")
|
||||
return
|
||||
items = [
|
||||
("百世", "password", (cfg.get("baishi", {}) or {}).get("password", "")),
|
||||
("韵达", "username", (cfg.get("yunda", {}) or {}).get("username", "")),
|
||||
("韵达", "password", (cfg.get("yunda", {}) or {}).get("password", "")),
|
||||
("安能", "app_path", (cfg.get("anneng", {}) or {}).get("app_path", "")),
|
||||
]
|
||||
seeded = []
|
||||
for site, key, val in items:
|
||||
if val and not state_store.get_setting(site, key):
|
||||
state_store.set_setting(site, key, str(val))
|
||||
seeded.append(f"{site}.{key}")
|
||||
if seeded:
|
||||
print(f">> [seed] 从 config.yaml 灌入站点配置: {', '.join(seeded)}")
|
||||
|
||||
|
||||
def launch_and_prepare(debug_mode=False, debug_target=""):
|
||||
"""启动 Playwright + 各站 page + 就绪轮询 + 弹窗清理 + 心跳初值,返回 RuntimeContext。
|
||||
|
||||
必须在"持有 Playwright 的线程"调用(交互模式主线程 / 服务模式 worker 线程)。
|
||||
阻塞至所有站点登录就绪才返回。
|
||||
"""
|
||||
# 0. 状态库建表/迁移(须在 reset_login_states 等读写新字段的调用之前)
|
||||
# 0. 状态库建表/迁移 + 从 config.yaml 灌入站点配置(须在 reset_login_states 等之前)
|
||||
state_store.init_db()
|
||||
seed_legacy_config()
|
||||
|
||||
# 1. 读 config(anneng.app_path)
|
||||
anneng_app_path = ""
|
||||
try:
|
||||
if os.path.exists(CONFIG_PATH):
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||
config = yaml.safe_load(f) or {}
|
||||
anneng_app_path = (config.get("anneng", {}) or {}).get("app_path", "")
|
||||
except Exception as e:
|
||||
print(f"⚠️ 读取 config.yaml 异常: {e}")
|
||||
# 1. 安能 Electron 应用路径(state.db,前端站点配置;seed 已灌入)
|
||||
anneng_app_path = state_store.get_setting("安能", "app_path")
|
||||
|
||||
# 2. 确定要挂载的网页站点 + 安能标记
|
||||
anneng_active = False
|
||||
|
||||
Reference in New Issue
Block a user