removed unnessesary features
This commit is contained in:
@@ -14,8 +14,6 @@ def get_db():
|
|||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
# your-very-long-random-admin-key
|
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
conn.execute("""
|
conn.execute("""
|
||||||
|
|||||||
@@ -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):
|
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 {}
|
event.data = event.data or {}
|
||||||
# Inject game name into event data as a tag
|
|
||||||
event.data["game"] = game
|
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
|
return event
|
||||||
@@ -32,10 +32,7 @@ def write_event(event) -> bool:
|
|||||||
p = Point(event.type).time(event.time * 1_000_000_000)
|
p = Point(event.type).time(event.time * 1_000_000_000)
|
||||||
p.tag("game", event.data.get("game", "unknown"))
|
p.tag("game", event.data.get("game", "unknown"))
|
||||||
p.tag("serverId", event.serverId)
|
p.tag("serverId", event.serverId)
|
||||||
# Optional tags
|
# Write all data fields as InfluxDB fields (no game-specific tags)
|
||||||
if "oreType" in event.data:
|
|
||||||
p.tag("oreType", event.data["oreType"])
|
|
||||||
# Write all numeric/string fields
|
|
||||||
for k, v in event.data.items():
|
for k, v in event.data.items():
|
||||||
if isinstance(v, (int, float, str, bool)):
|
if isinstance(v, (int, float, str, bool)):
|
||||||
p.field(k, v)
|
p.field(k, v)
|
||||||
|
|||||||
@@ -34,11 +34,22 @@ async def health():
|
|||||||
|
|
||||||
@app.post("/api/log")
|
@app.post("/api/log")
|
||||||
async def ingest_event(payload: Event | BatchEvents, game: str = Depends(verify_api_key)):
|
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):
|
if isinstance(payload, BatchEvents):
|
||||||
for event in payload.events:
|
for event in payload.events:
|
||||||
|
check_event(event)
|
||||||
enriched = enrich_event(event, game)
|
enriched = enrich_event(event, game)
|
||||||
write_event(enriched)
|
write_event(enriched)
|
||||||
else:
|
else:
|
||||||
|
check_event(payload)
|
||||||
enriched = enrich_event(payload, game)
|
enriched = enrich_event(payload, game)
|
||||||
write_event(enriched)
|
write_event(enriched)
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import Any, List, Optional
|
|||||||
|
|
||||||
class Event(BaseModel):
|
class Event(BaseModel):
|
||||||
type: str
|
type: str
|
||||||
time: int # unix timestamp
|
time: int
|
||||||
serverId: str
|
serverId: str
|
||||||
data: Optional[dict] = {}
|
data: Optional[dict] = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user