feat: 后台课程清单管理和自动同步

This commit is contained in:
2026-11-15 00:48:03 +08:00
parent 9f44082c8a
commit 98c11f42d8
7 changed files with 669 additions and 6 deletions
+25
View File
@@ -10,6 +10,7 @@ from admin.identity import identity
from admin.session import admin_session_active, clear_admin_session
from admin.settings import SettingsError, load_config, login_config_view, save_settings, settings_view
from admin.users import check_all, check_employee, delete_user, list_users, read_credentials, set_paused
from euniv.courses import course_page, request_course_sync_now
from euniv.db import get_db
public_router = APIRouter()
@@ -60,6 +61,30 @@ def admin_logout(response: Response) -> dict:
return {"ok": True}
@admin_router.post("/courses/load")
def post_courses_load(_: str = Depends(require_admin)) -> dict:
state = request_course_sync_now()
if state == "empty":
raise HTTPException(status_code=400, detail="没有可用的登录凭证")
if state == "disabled":
raise HTTPException(status_code=400, detail="课程清单没有获取到。")
return {"running": state in {"start", "busy"}}
@admin_router.get("/courses")
def get_courses(
q: str = "",
kind: str = "",
offset: int = 0,
limit: int = 50,
db: Session = Depends(get_db),
_: str = Depends(require_admin),
) -> dict:
bounded = min(max(limit, 1), 100)
start = max(offset, 0)
return course_page(db, q, start, bounded, kind)
@admin_router.get("/users")
def get_users(db: Session = Depends(get_db), _: str = Depends(require_admin)) -> list[dict]:
return list_users(db)