diff --git a/api/app/auth.py b/api/app/auth.py index 9ac44b6..c8f3109 100644 --- a/api/app/auth.py +++ b/api/app/auth.py @@ -14,8 +14,6 @@ def get_db(): conn.row_factory = sqlite3.Row return conn -# your-very-long-random-admin-key - def init_db(): conn = get_db() conn.execute(""" diff --git a/api/app/enrichment.py b/api/app/enrichment.py index 6039bb8..f3445f2 100644 --- a/api/app/enrichment.py +++ b/api/app/enrichment.py @@ -1,17 +1,5 @@ -def classify_price(robux: int) -> str: - if robux <= 99: - return "low" - elif robux <= 499: - return "medium" - else: - return "high" - def enrich_event(event, game: str): - """Adds game tag and derived fields.""" + """Add the game tag to the event. All other data passes through unchanged.""" event.data = event.data or {} - # Inject game name into event data as a tag event.data["game"] = game - # Derive price group for robux purchases - if event.type == "robux_purchase" and "robux" in event.data: - event.data["priceGroup"] = classify_price(event.data["robux"]) return event \ No newline at end of file diff --git a/api/app/influx.py b/api/app/influx.py index 3865132..4797df9 100644 --- a/api/app/influx.py +++ b/api/app/influx.py @@ -32,10 +32,7 @@ def write_event(event) -> bool: p = Point(event.type).time(event.time * 1_000_000_000) p.tag("game", event.data.get("game", "unknown")) p.tag("serverId", event.serverId) - # Optional tags - if "oreType" in event.data: - p.tag("oreType", event.data["oreType"]) - # Write all numeric/string fields + # Write all data fields as InfluxDB fields (no game-specific tags) for k, v in event.data.items(): if isinstance(v, (int, float, str, bool)): p.field(k, v) diff --git a/api/app/main.py b/api/app/main.py index ef83de5..15d57be 100644 --- a/api/app/main.py +++ b/api/app/main.py @@ -34,11 +34,22 @@ async def health(): @app.post("/api/log") async def ingest_event(payload: Event | BatchEvents, game: str = Depends(verify_api_key)): + def check_event(e: Event): + if not e.type or not e.type.strip(): + raise HTTPException(400, "Event type is required") + if not e.serverId: + raise HTTPException(400, "serverId is required") + if e.time <= 0: + raise HTTPException(400, "Invalid timestamp") + # Optionally refuse huge data (e.g., >1KB per event) + if isinstance(payload, BatchEvents): for event in payload.events: + check_event(event) enriched = enrich_event(event, game) write_event(enriched) else: + check_event(payload) enriched = enrich_event(payload, game) write_event(enriched) return {"success": True} diff --git a/api/app/models.py b/api/app/models.py index 60adec8..554eac6 100644 --- a/api/app/models.py +++ b/api/app/models.py @@ -3,7 +3,7 @@ from typing import Any, List, Optional class Event(BaseModel): type: str - time: int # unix timestamp + time: int serverId: str data: Optional[dict] = {}