fix database insert and validation
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
This commit is contained in:
@@ -27,6 +27,7 @@ def _db_text(value: Any) -> Any:
|
||||
|
||||
def _serialize_row_for_broadcast(row: Dict[str, Any]) -> Dict[str, Any]:
|
||||
serialized = dict(row)
|
||||
_normalize_json_fields(serialized)
|
||||
|
||||
raw_val = serialized.get("raw")
|
||||
if isinstance(raw_val, (bytes, bytearray)):
|
||||
@@ -40,6 +41,18 @@ def _serialize_row_for_broadcast(row: Dict[str, Any]) -> Dict[str, Any]:
|
||||
return serialized
|
||||
|
||||
|
||||
def _normalize_json_fields(payload: Dict[str, Any]) -> None:
|
||||
for key in ("dpi_metadata", "telemetry_metadata"):
|
||||
value = payload.get(key)
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
parsed = json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
if isinstance(parsed, dict):
|
||||
payload[key] = parsed
|
||||
|
||||
|
||||
class DatabasePool:
|
||||
"""Asyncpg connection pool wrapper used by the packet APIs."""
|
||||
|
||||
@@ -239,6 +252,7 @@ class DatabasePool:
|
||||
result: List[PacketDBModel] = []
|
||||
for row in rows:
|
||||
data = dict(row)
|
||||
_normalize_json_fields(data)
|
||||
|
||||
raw_val = data.get("raw")
|
||||
if isinstance(raw_val, (bytes, bytearray)):
|
||||
|
||||
Reference in New Issue
Block a user