feat: 账号可配置 HTTP/HTTPS/SOCKS 代理

This commit is contained in:
2026-11-15 01:21:17 +08:00
parent 1141df17f7
commit e9a1e9b315
15 changed files with 848 additions and 55 deletions
+14 -4
View File
@@ -68,6 +68,16 @@ def _persist(db: Session, employee_id: str, password: str, client: EunivClient,
db.commit()
def _client(factory, employee_id: str, password: str, account: Account | None = None):
from euniv.proxy import url_of
proxy = url_of(account) if account is not None else None
try:
return factory(employee_id, password, proxy)
except TypeError:
return factory(employee_id, password)
def login_and_store(
db: Session,
employee_id: str,
@@ -83,7 +93,7 @@ def login_and_store(
_request_course_sync(employee_id)
return {"employee_id": employee_id}
_drop_employee(employee_id)
client = client_factory(employee_id, password)
client = _client(client_factory, employee_id, password, account)
held = False
try:
try:
@@ -102,7 +112,7 @@ def login_and_store(
def _credential_still_valid(account: Account, client_factory) -> bool:
client = client_factory(account.employee_id, decrypt_secret(account.password_cipher))
client = _client(client_factory, account.employee_id, decrypt_secret(account.password_cipher), account)
try:
client.restore(json.loads(decrypt_secret(account.credential_cipher)))
return bool(client.credential_alive())
@@ -172,7 +182,7 @@ def _live(db: Session, employee_id: str, client_factory, read):
raise RuntimeError("请先登录")
credential = json.loads(decrypt_secret(account.credential_cipher)) if account.credential_cipher else {}
attempts = _auto_attempts(db)
client = client_factory(employee_id, decrypt_secret(account.password_cipher))
client = _client(client_factory, employee_id, decrypt_secret(account.password_cipher), account)
try:
if credential.get("yxt_token"):
client.restore(credential)
@@ -237,7 +247,7 @@ def _refresh_one(employee_id: str, attempts: int, client_factory) -> None:
try:
password = decrypt_secret(account.password_cipher)
previous = json.loads(decrypt_secret(account.credential_cipher))
client = client_factory(employee_id, password)
client = _client(client_factory, employee_id, password, account)
client.restore(previous)
if client.credential_alive():
updated = client.export_credential()