Offer the current exercise through an explicit API switch.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m42s

The exercise list turns the live catalog on or off for the caller's edit rights. A distribution key reads that current selection and the changes since its last cursor.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-23 15:37:25 +01:00
1 parent 4ad62b6e38
commit b59b7eae16
13 files changed
+488 -5

No files matched your search

+90
View File
@@ -226,6 +226,96 @@ def decode_cursor(secret: str, recipient_id: str, token: Optional[str]) -> int:
raise InvalidCursor() from exc
def catalog_available(offered: bool, in_scope: bool) -> bool:
"""Der aktuelle Abruf liefert eine Übung nur bei ausdrücklicher Auswahl und passendem Schlüsselumfang."""
return bool(offered) and bool(in_scope)
def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) -> dict:
"""Aktueller Übungsstand. Die Reihenfolge der Varianten und Medien gehört zum Inhalt."""
ordered_variants = sorted(
variants,
key=lambda item: (item.get("sequence_order") is None, item.get("sequence_order") or 0, int(item.get("id") or 0)),
)
ordered_media = sorted(
media,
key=lambda item: (item.get("sort_order") is None, item.get("sort_order") or 0, int(item.get("id") or 0)),
)
return {
"source_id": str(exercise.get("public_id")),
"title": exercise.get("title") or "",
"summary": plaintext(exercise.get("summary")),
"goal": plaintext(exercise.get("goal")),
"execution": plaintext(exercise.get("execution")),
"preparation": plaintext(exercise.get("preparation")),
"trainer_notes": plaintext(exercise.get("trainer_notes")),
"equipment": _equipment_text(exercise) or "",
"duration_min": exercise.get("duration_min"),
"duration_max": exercise.get("duration_max"),
"variants": [
{
"id": str(item.get("public_id")),
"name": item.get("variant_name") or "",
"description": plaintext(item.get("description")),
"execution_changes": plaintext(item.get("execution_changes")),
"sequence_order": item.get("sequence_order"),
}
for item in ordered_variants
],
"media": [
{
"id": str(item.get("public_id")),
"media_type": item.get("media_type") or "",
"title": item.get("title") or "",
"sort_order": item.get("sort_order"),
}
for item in ordered_media
],
}
def catalog_hash(document: dict) -> str:
return sha256_bytes(canonical_json(document))
def catalog_changes(previous: dict, current: dict) -> list[dict]:
"""Differenz seit dem letzten erfolgreichen Abruf. Gleiche Prüfsumme gilt als unverändert."""
changes = []
for source_id in sorted(current):
digest = current[source_id]
if source_id not in previous:
changes.append({"source_id": source_id, "change": "added", "content_hash": digest})
elif previous[source_id] != digest:
changes.append({"source_id": source_id, "change": "updated", "content_hash": digest})
for source_id in sorted(previous):
if source_id not in current:
changes.append({"source_id": source_id, "change": "removed"})
return changes
def encode_catalog_cursor(secret: str, binding_id: str, snapshot_id: str) -> str:
payload = f"{binding_id}:{snapshot_id}".encode("utf-8")
sig = hmac.new(secret.encode("utf-8"), payload, hashlib.sha256).hexdigest()
raw = payload + b"." + sig.encode("ascii")
return base64.urlsafe_b64encode(raw).decode("ascii").rstrip("=")
def decode_catalog_cursor(secret: str, binding_id: str, token: Optional[str]) -> str:
pad = "=" * (-len(token) % 4)
try:
raw = base64.urlsafe_b64decode(token + pad)
payload, sig = raw.rsplit(b".", 1)
expected = hmac.new(secret.encode("utf-8"), payload, hashlib.sha256).hexdigest().encode("ascii")
if not hmac.compare_digest(sig, expected):
raise ValueError("sig")
bound, snapshot_id = payload.decode("utf-8").split(":", 1)
if bound != str(binding_id):
raise ValueError("channel")
return snapshot_id
except Exception as exc:
raise InvalidCursor() from exc
class InvalidCursor(Exception):
pass