fix: 全站 ruff 清零 — 77 errors → 0
Fixes: - F821: install.py site_url 未定义(NameError)、sync_v2.py os 未导入、script_jobs.py LOG f-string - F401: 移除 22 个未使用导入(models/__init__.py、install.py、auth.py 等) - B904: 20 个 except 块 raise 添加 from e/from None - S110: 20 个有意的 try-except-pass 添加 noqa 注释(SSH清理/DDL幂等/WS断连) - B007: 3 个未使用循环变量重命名(dirs→_dirs、server_id→_server_id) - F541: 3 个无占位符 f-string 修正 - F841: auth.py 未使用 ip_address 变量移除 - S105: auth_service.py Redis key prefix 误报 noqa - B023: script_execution_flush.py 循环变量绑定修复 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from server.infrastructure.database.push_schedule_repo import PushScheduleReposi
|
||||
from server.infrastructure.database.password_preset_repo import PasswordPresetRepositoryImpl
|
||||
from server.infrastructure.database.ssh_key_preset_repo import SshKeyPresetRepositoryImpl
|
||||
from server.infrastructure.database.audit_log_repo import AuditLogRepositoryImpl
|
||||
from server.domain.models import Setting, PushSchedule, PushRetryJob, PasswordPreset, SshKeyPreset, AuditLog, Admin
|
||||
from server.domain.models import PushSchedule, PushRetryJob, PasswordPreset, SshKeyPreset, AuditLog, Admin
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -327,7 +327,7 @@ async def reveal_preset(
|
||||
try:
|
||||
plaintext = decrypt_value(preset.encrypted_pw)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=500, detail="解密失败")
|
||||
raise HTTPException(status_code=500, detail="解密失败") from None
|
||||
|
||||
audit_repo = AuditLogRepositoryImpl(db)
|
||||
await audit_repo.create(AuditLog(
|
||||
@@ -472,7 +472,7 @@ async def reveal_ssh_key_preset(
|
||||
try:
|
||||
plaintext = decrypt_value(preset.encrypted_private_key)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=500, detail="解密失败")
|
||||
raise HTTPException(status_code=500, detail="解密失败") from None
|
||||
|
||||
audit_repo = AuditLogRepositoryImpl(db)
|
||||
await audit_repo.create(AuditLog(
|
||||
@@ -689,7 +689,7 @@ async def telegram_get_chats(
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=502, detail=f"请求失败: {e}")
|
||||
raise HTTPException(status_code=502, detail=f"请求失败: {e}") from e
|
||||
|
||||
# Extract unique chats
|
||||
seen: set[int] = set()
|
||||
@@ -748,11 +748,11 @@ async def parse_subscription(
|
||||
raise HTTPException(status_code=400, detail=f"订阅链接返回 HTTP {resp.status_code}")
|
||||
raw = resp.text
|
||||
except httpx.TimeoutException:
|
||||
raise HTTPException(status_code=400, detail="请求订阅链接超时(15s)")
|
||||
raise HTTPException(status_code=400, detail="请求订阅链接超时(15s)") from None
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=f"获取订阅失败: {e}")
|
||||
raise HTTPException(status_code=400, detail=f"获取订阅失败: {e}") from e
|
||||
|
||||
hosts = parse_subscription_content(raw)
|
||||
if not hosts:
|
||||
@@ -914,7 +914,7 @@ async def get_ip_allowlist(
|
||||
):
|
||||
"""Return full allowlist state."""
|
||||
from server.config import settings as _settings
|
||||
from server.background.ip_allowlist_refresh import get_last_refresh_time, get_subscription_count
|
||||
from server.background.ip_allowlist_refresh import get_last_refresh_time
|
||||
|
||||
allowlist_on = (_settings.LOGIN_ALLOWLIST_ENABLED or "false").lower() in ("true","1","yes","on")
|
||||
sub_ips_raw = _settings.LOGIN_SUBSCRIPTION_IPS or ""
|
||||
|
||||
Reference in New Issue
Block a user