feat: save registered accounts to postgres

This commit is contained in:
mmc
2026-03-19 14:32:17 +08:00
parent 6a250fe6a1
commit 2904e43b1f
11 changed files with 235 additions and 4 deletions

View File

@@ -43,6 +43,14 @@ DEFAULT_CONFIG: Dict[str, Any] = {
"proxy": "",
"auto_register": False,
"auto_register_max_per_loop": 1,
"db_enabled": False,
"db_host": "150.158.105.6",
"db_port": 54321,
"db_name": "postgres",
"db_user": "postgres",
"db_password": "",
"db_table": "registered_accounts",
"db_source": "standalone_cli",
"proxy_pool_enabled": True,
"proxy_pool_api_url": "https://zenproxy.top/api/fetch",
"proxy_pool_auth_mode": "query",
@@ -179,6 +187,17 @@ def normalize_config(cfg: Dict[str, Any]) -> Dict[str, Any]:
cfg["auto_register_max_per_loop"] = max(1, min(int(cfg.get("auto_register_max_per_loop", 1)), 20))
except (TypeError, ValueError):
cfg["auto_register_max_per_loop"] = 1
cfg["db_enabled"] = _as_bool(cfg.get("db_enabled", False), default=False)
cfg["db_host"] = str(cfg.get("db_host", DEFAULT_CONFIG["db_host"]) or DEFAULT_CONFIG["db_host"]).strip()
try:
cfg["db_port"] = max(1, int(cfg.get("db_port", DEFAULT_CONFIG["db_port"]) or DEFAULT_CONFIG["db_port"]))
except (TypeError, ValueError):
cfg["db_port"] = DEFAULT_CONFIG["db_port"]
cfg["db_name"] = str(cfg.get("db_name", DEFAULT_CONFIG["db_name"]) or DEFAULT_CONFIG["db_name"]).strip()
cfg["db_user"] = str(cfg.get("db_user", DEFAULT_CONFIG["db_user"]) or DEFAULT_CONFIG["db_user"]).strip()
cfg["db_password"] = str(cfg.get("db_password", DEFAULT_CONFIG["db_password"]) or DEFAULT_CONFIG["db_password"]).strip()
cfg["db_table"] = str(cfg.get("db_table", DEFAULT_CONFIG["db_table"]) or DEFAULT_CONFIG["db_table"]).strip()
cfg["db_source"] = str(cfg.get("db_source", DEFAULT_CONFIG["db_source"]) or DEFAULT_CONFIG["db_source"]).strip()
cfg["proxy_pool_enabled"] = _as_bool(cfg.get("proxy_pool_enabled", True), default=True)
proxy_pool_api_url = str(cfg.get("proxy_pool_api_url", DEFAULT_CONFIG["proxy_pool_api_url"]) or "").strip()
cfg["proxy_pool_api_url"] = proxy_pool_api_url or DEFAULT_CONFIG["proxy_pool_api_url"]