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
+30
View File
@@ -0,0 +1,30 @@
"""同一账号同时学习的课程数。默认 1,最多 8。"""
from __future__ import annotations
DEFAULT = 1
MAX = 8
class CourseWorkersError(ValueError):
"""同时学习课程数不符合要求。"""
def validate(value: object) -> int:
if not isinstance(value, int) or isinstance(value, bool) or not DEFAULT <= value <= MAX:
raise CourseWorkersError(f"同时学习课程数须为 {DEFAULT} 到 {MAX} 的整数")
return value
def apply(account, value: object) -> None:
account.course_workers = validate(value)
def of(account) -> int:
raw = int(getattr(account, "course_workers", DEFAULT) or DEFAULT)
return max(DEFAULT, min(MAX, raw))
def view_of(account) -> dict:
workers = of(account)
return {"workers": workers, "max": MAX, "recommended": workers == DEFAULT}