Ship Steam login, D1 player sync, and cached「我」dashboard.

Players get a fast TTL-backed homepage (local profile / Cloudflare D1) with dense UI polish; login unlocks /home without blocking on every OpenDota refresh.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
voson
2026-08-01 01:24:30 +08:00
co-authored by Cursor
parent 4a61aeeb26
commit f5b7011c45
65 changed files with 7304 additions and 552 deletions
+50
View File
@@ -0,0 +1,50 @@
"""TTL helpers for player homepage cache-first serving."""
from __future__ import annotations
import sys
import unittest
from datetime import datetime, timedelta, timezone
from pathlib import Path
PC = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(PC))
from player_pages import ( # noqa: E402
profile_fetched_at,
profile_has_payload,
profile_is_stale,
)
def _iso_ago(seconds: int) -> str:
t = datetime.now(timezone.utc) - timedelta(seconds=seconds)
return t.strftime("%Y-%m-%dT%H:%M:%SZ")
class PlayerPagesCacheTests(unittest.TestCase):
def test_has_payload_career(self):
self.assertTrue(profile_has_payload({"career": {"games": 10}}))
self.assertFalse(profile_has_payload({"career": {"games": 0}}))
def test_has_payload_recent(self):
self.assertTrue(profile_has_payload({"recent": [{"match_id": 1}]}))
self.assertFalse(profile_has_payload({"recent": []}))
def test_fetched_at_prefers_availability(self):
p = {
"availability": {"fetched_at": "2026-01-01T00:00:00Z"},
"enriched_at": "2026-01-02T00:00:00Z",
}
self.assertEqual(profile_fetched_at(p), "2026-01-01T00:00:00Z")
def test_stale_ttl(self):
fresh = {"enriched_at": _iso_ago(60)}
old = {"enriched_at": _iso_ago(1200)}
self.assertFalse(profile_is_stale(fresh, 600))
self.assertTrue(profile_is_stale(old, 600))
self.assertTrue(profile_is_stale({}, 600))
if __name__ == "__main__":
unittest.main()