Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes. Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
941 B
Python
29 lines
941 B
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Header
|
|
from typing import Annotated
|
|
|
|
from app.schemas.track import TrackBatchBody
|
|
from app.services.store import store
|
|
from app.services.track import ingest_events
|
|
|
|
router = APIRouter(prefix="/api/track", tags=["track"])
|
|
|
|
|
|
@router.post("")
|
|
@router.post("/")
|
|
async def track_batch(
|
|
body: TrackBatchBody,
|
|
authorization: Annotated[str | None, Header()] = None,
|
|
):
|
|
"""小程序埋点上报。可匿名;若带 Bearer 则绑定 openid。"""
|
|
openid = (body.openid or "").strip() or None
|
|
if authorization and authorization.startswith("Bearer "):
|
|
token = authorization.removeprefix("Bearer ").strip()
|
|
user = store.get_user_by_token(token)
|
|
if user:
|
|
openid = user.get("openid") or openid
|
|
|
|
events = [e.model_dump() for e in body.events]
|
|
return await ingest_events(events, openid=openid, client=body.client or "miniapp")
|