feat: show current duty students and shift countdown on activity wall

This commit is contained in:
2026-11-06 14:19:16 +08:00
parent 12bcd4a62c
commit 867443163a
9 changed files with 175 additions and 7 deletions
+12 -1
View File
@@ -19,6 +19,7 @@ import uuid
from html import escape
from ipaddress import ip_address
from contextlib import asynccontextmanager
from datetime import datetime
from pathlib import Path
from typing import Any, Literal, Optional
@@ -36,7 +37,7 @@ from sqlalchemy.dialects.sqlite import insert as sqlite_insert
from .models import activities, auth_limits, email_verifications, join_links, metadata, participations, sessions, users
from .security import hash_password, new_token, token_digest, verify_password
from .backup import backup_loop, parse_time
from .duty import reminder_loop
from .duty import BEIJING, duty_status, load_schedule, reminder_loop
BASE_DIR = Path(__file__).resolve().parent
PROJECT_DIR = BASE_DIR.parent
@@ -1145,6 +1146,16 @@ async def update_me(payload: ProfileIn, user: dict = Depends(current_user), db:
# ---------------------------------------------------------------- 成员
@app.get("/api/duty/current")
async def current_duty(_viewer: dict = Depends(current_user)) -> dict:
path = Path(os.getenv("WORKLOG_DUTY_SCHEDULE", str(PROJECT_DIR / "duty/schedule.json")))
if not path.exists():
return duty_status({"enabled": False}, datetime.now(BEIJING))
try:
return duty_status(load_schedule(path), datetime.now(BEIJING))
except (ValueError, KeyError, TypeError, OSError) as exc:
raise HTTPException(status_code=503, detail="值班安排暂时无法读取") from exc
@app.get("/api/stats/overview")
async def overview(db: AsyncSession = Depends(get_db), _viewer: dict = Depends(current_user)) -> dict:
members = int((await db.execute(select(func.count()).select_from(users))).scalar() or 0)