feat: 账号可设置同时学习课程数并支持关闭代理
This commit is contained in:
+23
-2
@@ -11,6 +11,10 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from euniv.crypto import decrypt_secret
|
||||
from euniv.models import Account
|
||||
from euniv.course_workers import CourseWorkersError
|
||||
from euniv.course_workers import apply as apply_workers
|
||||
from euniv.course_workers import of as workers_of
|
||||
from euniv.course_workers import view_of as workers_view
|
||||
from euniv.proxy import ProxyError, apply, clear, summary_of, url_of, view_of
|
||||
from euniv.study_window import StudyWindowError
|
||||
from euniv.study_window import apply as apply_start
|
||||
@@ -76,6 +80,7 @@ def list_users(db: Session) -> list[dict]:
|
||||
"study_start_hour": int(account.study_start_hour or 0),
|
||||
"study_start_minute": int(account.study_start_minute or 0),
|
||||
"study_start_second": int(account.study_start_second or 0),
|
||||
"course_workers": workers_of(account),
|
||||
}
|
||||
for account in accounts
|
||||
]
|
||||
@@ -202,8 +207,8 @@ def set_proxy(
|
||||
db: Session,
|
||||
employee_ids: list[str],
|
||||
scheme: str,
|
||||
host: str,
|
||||
port: int,
|
||||
host: str = "",
|
||||
port: object = None,
|
||||
username: str = "",
|
||||
password: str | None = None,
|
||||
) -> dict:
|
||||
@@ -249,6 +254,22 @@ def set_study_start(
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
def read_course_workers(db: Session, employee_id: str) -> dict:
|
||||
return workers_view(_require(db, employee_id))
|
||||
|
||||
|
||||
def set_course_workers(db: Session, employee_ids: list[str], workers: int) -> dict:
|
||||
accounts = _accounts_by_ids(db, employee_ids)
|
||||
try:
|
||||
for account in accounts:
|
||||
apply_workers(account, workers)
|
||||
except CourseWorkersError as exc:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
db.commit()
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
def delete_user(db: Session, employee_id: str) -> dict:
|
||||
account = _require(db, employee_id)
|
||||
db.delete(account)
|
||||
|
||||
Reference in New Issue
Block a user