style: 统一 Ruff 代码格式

This commit is contained in:
yml2213
2026-08-30 21:04:52 +08:00
parent c891ac982e
commit 47e19ed7b2
90 changed files with 5574 additions and 2350 deletions
+30 -15
View File
@@ -8,7 +8,11 @@ from typing import Optional
from sqlalchemy.orm import Session
from core.douyu.proxy import resolve_working_proxy, verify_proxy_url, parse_proxy_response
from core.douyu.proxy import (
resolve_working_proxy,
verify_proxy_url,
parse_proxy_response,
)
from core.douyu.proxy_platforms import create_adapter, get_platform_labels
from core.douyu.proxy_platforms.base import _get_local_exit_ip
from ..models import ProxyConfig as ProxyConfigModel, AuditLog
@@ -20,8 +24,8 @@ def _build_whitelist_params(cfg: ProxyConfigModel) -> dict:
Returns:
{"whitelist_platform": str, "whitelist_credentials": dict|None}
"""
platform = getattr(cfg, 'whitelist_platform', None) or "xiequ"
credentials = getattr(cfg, 'whitelist_credentials', None)
platform = getattr(cfg, "whitelist_platform", None) or "xiequ"
credentials = getattr(cfg, "whitelist_credentials", None)
# 向后兼容:旧字段有值但新字段为空时,自动迁移
if not credentials and cfg.whitelist_uid and cfg.whitelist_ukey:
@@ -57,7 +61,10 @@ class ProxyService:
# 应用层自动迁移:旧字段有值但新字段为空时,填充新字段
if cfg.whitelist_uid and cfg.whitelist_ukey and not cfg.whitelist_credentials:
cfg.whitelist_platform = "xiequ"
cfg.whitelist_credentials = {"uid": cfg.whitelist_uid, "ukey": cfg.whitelist_ukey}
cfg.whitelist_credentials = {
"uid": cfg.whitelist_uid,
"ukey": cfg.whitelist_ukey,
}
db.commit()
return cfg
@@ -65,7 +72,10 @@ class ProxyService:
@staticmethod
def update_config(
db: Session,
enabled, api_url, http, https,
enabled,
api_url,
http,
https,
whitelist_enabled,
whitelist_platform="xiequ",
whitelist_credentials=None,
@@ -96,12 +106,14 @@ class ProxyService:
db.refresh(cfg)
if current_user:
db.add(AuditLog(
user_id=current_user.id,
username=current_user.username,
action="proxy:update",
target="proxy_config",
))
db.add(
AuditLog(
user_id=current_user.id,
username=current_user.username,
action="proxy:update",
target="proxy_config",
)
)
db.commit()
return cfg
@@ -258,18 +270,21 @@ class ProxyService:
# 3. 检查并同步白名单
records = adapter.get_whitelist()
in_list = any(r.get('ip') == local_ip for r in records)
in_list = any(r.get("ip") == local_ip for r in records)
if records:
push("info", f"白名单共 {len(records)} 条记录")
if in_list:
record = next((r for r in records if r.get('ip') == local_ip), {})
memo = record.get('memo', '')
record = next((r for r in records if r.get("ip") == local_ip), {})
memo = record.get("memo", "")
if memo == adapter.memo:
push("success", f"本机IP {local_ip} 已在白名单中 (备注正确)")
else:
push("warning", f'本机IP {local_ip} 备注不匹配 (当前: "{memo}"),更新中...')
push(
"warning",
f'本机IP {local_ip} 备注不匹配 (当前: "{memo}"),更新中...',
)
sync_ok, sync_msg = adapter.sync_ip(local_ip)
push("success" if sync_ok else "error", f"白名单更新: {sync_msg}")
else: