Upload 67 files
Browse files
app/routes/__pycache__/auth.cpython-313.pyc
CHANGED
|
Binary files a/app/routes/__pycache__/auth.cpython-313.pyc and b/app/routes/__pycache__/auth.cpython-313.pyc differ
|
|
|
app/routes/__pycache__/user.cpython-313.pyc
CHANGED
|
Binary files a/app/routes/__pycache__/user.cpython-313.pyc and b/app/routes/__pycache__/user.cpython-313.pyc differ
|
|
|
app/routes/auth.py
CHANGED
|
@@ -8,7 +8,8 @@ from app.auth import get_current_admin, get_current_user, sign_in_admin, sign_in
|
|
| 8 |
from app.database import get_db
|
| 9 |
from app.models import Admin, Group, User
|
| 10 |
from app.security import hash_password, verify_password
|
| 11 |
-
from app.services.presence import should_write_presence, unix_seconds
|
|
|
|
| 12 |
from app.web import add_flash, local_now, redirect, render
|
| 13 |
|
| 14 |
|
|
@@ -173,6 +174,7 @@ def presence_ping(request: Request, db: Session = Depends(get_db)):
|
|
| 173 |
|
| 174 |
now = local_now()
|
| 175 |
wrote = False
|
|
|
|
| 176 |
if should_write_presence(request.session, now):
|
| 177 |
if admin:
|
| 178 |
admin.last_seen_at = now
|
|
@@ -183,6 +185,11 @@ def presence_ping(request: Request, db: Session = Depends(get_db)):
|
|
| 183 |
db.commit()
|
| 184 |
wrote = True
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
return JSONResponse(
|
| 187 |
{
|
| 188 |
"ok": True,
|
|
@@ -192,3 +199,5 @@ def presence_ping(request: Request, db: Session = Depends(get_db)):
|
|
| 192 |
headers={"Cache-Control": "no-store"},
|
| 193 |
)
|
| 194 |
|
|
|
|
|
|
|
|
|
| 8 |
from app.database import get_db
|
| 9 |
from app.models import Admin, Group, User
|
| 10 |
from app.security import hash_password, verify_password
|
| 11 |
+
from app.services.presence import is_online, should_write_presence, unix_seconds
|
| 12 |
+
from app.services.review_queue import rebalance_pending_reviews
|
| 13 |
from app.web import add_flash, local_now, redirect, render
|
| 14 |
|
| 15 |
|
|
|
|
| 174 |
|
| 175 |
now = local_now()
|
| 176 |
wrote = False
|
| 177 |
+
admin_was_online = bool(admin and is_online(admin.last_seen_at, now))
|
| 178 |
if should_write_presence(request.session, now):
|
| 179 |
if admin:
|
| 180 |
admin.last_seen_at = now
|
|
|
|
| 185 |
db.commit()
|
| 186 |
wrote = True
|
| 187 |
|
| 188 |
+
# Only rebalance on an offline -> online transition. Fresh uploads are handled
|
| 189 |
+
# at submit time, so this keeps the 5s heartbeat lightweight.
|
| 190 |
+
if admin and not admin_was_online:
|
| 191 |
+
rebalance_pending_reviews(db)
|
| 192 |
+
|
| 193 |
return JSONResponse(
|
| 194 |
{
|
| 195 |
"ok": True,
|
|
|
|
| 199 |
headers={"Cache-Control": "no-store"},
|
| 200 |
)
|
| 201 |
|
| 202 |
+
|
| 203 |
+
|
app/routes/user.py
CHANGED
|
@@ -17,7 +17,8 @@ from app.services.group_progress import (
|
|
| 17 |
pick_primary_submission,
|
| 18 |
)
|
| 19 |
from app.services.images import compress_to_limit, persist_submission_image, read_and_validate_upload
|
| 20 |
-
from app.services.leaderboard import build_leaderboard
|
|
|
|
| 21 |
from app.web import add_flash, local_now, redirect, render
|
| 22 |
|
| 23 |
|
|
@@ -200,6 +201,9 @@ async def submit_task(
|
|
| 200 |
submission.created_at = now
|
| 201 |
db.commit()
|
| 202 |
|
|
|
|
|
|
|
|
|
|
| 203 |
add_flash(request, "success", "小组图片已提交,等待管理员审核。")
|
| 204 |
return redirect(f"/activities/{activity_id}")
|
| 205 |
|
|
@@ -288,3 +292,4 @@ def activity_status(activity_id: int, request: Request, db: Session = Depends(ge
|
|
| 288 |
|
| 289 |
|
| 290 |
|
|
|
|
|
|
| 17 |
pick_primary_submission,
|
| 18 |
)
|
| 19 |
from app.services.images import compress_to_limit, persist_submission_image, read_and_validate_upload
|
| 20 |
+
from app.services.leaderboard import build_leaderboard
|
| 21 |
+
from app.services.review_queue import rebalance_pending_reviews
|
| 22 |
from app.web import add_flash, local_now, redirect, render
|
| 23 |
|
| 24 |
|
|
|
|
| 201 |
submission.created_at = now
|
| 202 |
db.commit()
|
| 203 |
|
| 204 |
+
# If admins are already online, dispatch the queued review immediately.
|
| 205 |
+
rebalance_pending_reviews(db)
|
| 206 |
+
|
| 207 |
add_flash(request, "success", "小组图片已提交,等待管理员审核。")
|
| 208 |
return redirect(f"/activities/{activity_id}")
|
| 209 |
|
|
|
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
+
|
app/services/__pycache__/review_queue.cpython-313.pyc
CHANGED
|
Binary files a/app/services/__pycache__/review_queue.cpython-313.pyc and b/app/services/__pycache__/review_queue.cpython-313.pyc differ
|
|
|
app/services/review_queue.py
CHANGED
|
@@ -32,6 +32,16 @@ def rebalance_pending_reviews(db: Session, activity_id: int | None = None) -> li
|
|
| 32 |
pending_submissions = pending_query.all()
|
| 33 |
admins = online_admins(db)
|
| 34 |
if not admins:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return pending_submissions
|
| 36 |
|
| 37 |
now = local_now()
|
|
@@ -69,3 +79,4 @@ def rebalance_pending_reviews(db: Session, activity_id: int | None = None) -> li
|
|
| 69 |
db.commit()
|
| 70 |
pending_submissions = pending_query.all()
|
| 71 |
return pending_submissions
|
|
|
|
|
|
| 32 |
pending_submissions = pending_query.all()
|
| 33 |
admins = online_admins(db)
|
| 34 |
if not admins:
|
| 35 |
+
changed = False
|
| 36 |
+
for submission in pending_submissions:
|
| 37 |
+
if submission.assigned_admin_id is None and submission.assigned_at is None:
|
| 38 |
+
continue
|
| 39 |
+
submission.assigned_admin_id = None
|
| 40 |
+
submission.assigned_at = None
|
| 41 |
+
changed = True
|
| 42 |
+
if changed:
|
| 43 |
+
db.commit()
|
| 44 |
+
pending_submissions = pending_query.all()
|
| 45 |
return pending_submissions
|
| 46 |
|
| 47 |
now = local_now()
|
|
|
|
| 79 |
db.commit()
|
| 80 |
pending_submissions = pending_query.all()
|
| 81 |
return pending_submissions
|
| 82 |
+
|