nomadro/apps/ebook/wemini/backend/app/routers/track.py
eric 626f6b19e8 Ship unified miniprogram H5/weapp parity and XHS offline portal.
Align Taro pages with Next hub/nav/book/community/VIP, pack the single-index Xiaohongshu portal with host-chrome safe areas, and refresh shared book content plus portal README constraints.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 09:37:03 +08:00

29 lines
937 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="/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")