fix: 一次保存学习配置,改代理后重开任务
This commit is contained in:
+8
-69
@@ -17,20 +17,16 @@ from admin.users import (
|
||||
list_users,
|
||||
read_credentials,
|
||||
read_proxy,
|
||||
read_course_workers,
|
||||
read_study_start,
|
||||
set_course_workers,
|
||||
set_paused,
|
||||
set_proxy,
|
||||
set_study_action,
|
||||
set_study_settings,
|
||||
set_study_start,
|
||||
)
|
||||
from euniv.courses import course_page, request_course_sync_now
|
||||
from euniv.db import get_db
|
||||
from euniv.proxy_pool import ProxyProbeError
|
||||
from euniv.proxy_pool import page as proxy_page
|
||||
from euniv.proxy_pool import probe_ids as probe_proxy_ids
|
||||
from euniv.proxy_pool import probe_state as proxy_probe_state
|
||||
from euniv.proxy_pool import request_probe as request_proxy_probe
|
||||
from euniv.proxy_pool import probe_one as probe_proxy_one
|
||||
from euniv.proxy_pool import request_refresh as request_proxy_refresh
|
||||
|
||||
@@ -57,32 +53,10 @@ class PauseBody(BaseModel):
|
||||
paused: bool
|
||||
|
||||
|
||||
class AdminProxyBody(BaseModel):
|
||||
employee_ids: list[str]
|
||||
scheme: str
|
||||
host: str = ""
|
||||
port: int | None = None
|
||||
username: str = ""
|
||||
password: str | None = None
|
||||
|
||||
|
||||
class AdminProxyClearBody(BaseModel):
|
||||
employee_ids: list[str]
|
||||
|
||||
|
||||
class AdminStudyStartBody(BaseModel):
|
||||
employee_ids: list[str]
|
||||
day: int
|
||||
hour: int
|
||||
minute: int
|
||||
second: int
|
||||
|
||||
|
||||
class AdminCourseWorkersBody(BaseModel):
|
||||
employee_ids: list[str]
|
||||
workers: int
|
||||
|
||||
|
||||
class AdminStudyActionBody(BaseModel):
|
||||
employee_ids: list[str]
|
||||
action: str
|
||||
@@ -185,10 +159,12 @@ def post_proxies_refresh(_: str = Depends(require_admin)) -> dict:
|
||||
|
||||
@admin_router.post("/proxies/probe")
|
||||
def post_proxies_probe(body: AdminProxyProbeBody, _: str = Depends(require_admin)) -> dict:
|
||||
try:
|
||||
return probe_proxy_ids(body.ids)
|
||||
except ProxyProbeError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
return request_proxy_probe(body.ids)
|
||||
|
||||
|
||||
@admin_router.get("/proxies/probe")
|
||||
def get_proxies_probe(_: str = Depends(require_admin)) -> dict:
|
||||
return proxy_probe_state()
|
||||
|
||||
|
||||
@admin_router.post("/proxies/{proxy_id}/probe")
|
||||
@@ -224,19 +200,6 @@ def post_refresh(
|
||||
return set_paused(db, employee_id, body.paused)
|
||||
|
||||
|
||||
@admin_router.put("/users/proxy")
|
||||
def put_users_proxy(body: AdminProxyBody, db: Session = Depends(get_db), _: str = Depends(require_admin)) -> dict:
|
||||
return set_proxy(
|
||||
db,
|
||||
body.employee_ids,
|
||||
body.scheme,
|
||||
body.host,
|
||||
body.port,
|
||||
body.username,
|
||||
body.password,
|
||||
)
|
||||
|
||||
|
||||
@admin_router.post("/users/proxy/clear")
|
||||
def post_users_proxy_clear(
|
||||
body: AdminProxyClearBody,
|
||||
@@ -251,30 +214,6 @@ def get_user_proxy(employee_id: str, db: Session = Depends(get_db), _: str = Dep
|
||||
return read_proxy(db, employee_id)
|
||||
|
||||
|
||||
@admin_router.put("/users/study-start")
|
||||
def put_users_study_start(
|
||||
body: AdminStudyStartBody, db: Session = Depends(get_db), _: str = Depends(require_admin)
|
||||
) -> dict:
|
||||
return set_study_start(db, body.employee_ids, body.day, body.hour, body.minute, body.second)
|
||||
|
||||
|
||||
@admin_router.get("/users/{employee_id}/study-start")
|
||||
def get_user_study_start(employee_id: str, db: Session = Depends(get_db), _: str = Depends(require_admin)) -> dict:
|
||||
return read_study_start(db, employee_id)
|
||||
|
||||
|
||||
@admin_router.put("/users/course-workers")
|
||||
def put_users_course_workers(
|
||||
body: AdminCourseWorkersBody, db: Session = Depends(get_db), _: str = Depends(require_admin)
|
||||
) -> dict:
|
||||
return set_course_workers(db, body.employee_ids, body.workers)
|
||||
|
||||
|
||||
@admin_router.get("/users/{employee_id}/course-workers")
|
||||
def get_user_course_workers(employee_id: str, db: Session = Depends(get_db), _: str = Depends(require_admin)) -> dict:
|
||||
return read_course_workers(db, employee_id)
|
||||
|
||||
|
||||
@admin_router.post("/users/study")
|
||||
def post_users_study(
|
||||
body: AdminStudyActionBody, db: Session = Depends(get_db), _: str = Depends(require_admin)
|
||||
|
||||
Reference in New Issue
Block a user