feat: 账号可设置同时学习课程数并支持关闭代理

This commit is contained in:
2026-11-15 01:48:39 +08:00
parent ecd774507f
commit aa26d00c60
14 changed files with 564 additions and 119 deletions
+12 -3
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
from urllib.parse import quote, urlparse
SCHEMES = ("http", "https", "socks4", "socks5", "socks5h")
OFF_SCHEMES = ("", "off", "none", "direct", "close")
class ProxyError(ValueError):
@@ -61,14 +62,19 @@ def validate_parts(scheme: str, host: str, port: object, username: str = "") ->
return kind, address, port, user
def is_off(scheme: str | None) -> bool:
return (scheme or "").strip().lower() in OFF_SCHEMES
def enabled(account) -> bool:
return bool(account.proxy_scheme and account.proxy_host and account.proxy_port)
def view_of(account) -> dict:
on = enabled(account)
return {
"enabled": enabled(account),
"scheme": account.proxy_scheme or "http",
"enabled": on,
"scheme": account.proxy_scheme if on else "off",
"host": account.proxy_host or "",
"port": int(account.proxy_port) if account.proxy_port else None,
"username": account.proxy_username or "",
@@ -99,7 +105,10 @@ def url_of(account) -> str | None:
)
def apply(account, scheme: str, host: str, port: object, username: str = "", password: str | None = None) -> None:
def apply(account, scheme: str, host: str = "", port: object = None, username: str = "", password: str | None = None) -> None:
if is_off(scheme):
clear(account)
return
kind, address, number, user = validate_parts(scheme, host, port, username)
if password is not None and len(str(password)) > 256:
raise ProxyError("代理密码过长")