This commit is contained in:
Joel Krauska
2025-11-25 18:12:04 -08:00
parent 7edb7b5c38
commit 8bea2bd744
3 changed files with 15 additions and 23 deletions

View File

@@ -27,10 +27,10 @@ async def get_fuzzy_nodes(query):
async def get_packets(
from_node_id=None,
to_node_id=None,
node_id=None, # legacy: match either from OR to
node_id=None, # legacy: match either from OR to
portnum=None,
after=None,
contains=None, # NEW: SQL-level substring match
contains=None, # NEW: SQL-level substring match
limit=50,
):
"""
@@ -40,7 +40,6 @@ async def get_packets(
"""
async with database.async_session() as session:
stmt = select(models.Packet)
conditions = []
@@ -55,10 +54,7 @@ async def get_packets(
# Legacy node ID filter: match either direction
if node_id is not None:
conditions.append(
or_(
models.Packet.from_node_id == node_id,
models.Packet.to_node_id == node_id
)
or_(models.Packet.from_node_id == node_id, models.Packet.to_node_id == node_id)
)
# Port filter
@@ -72,9 +68,7 @@ async def get_packets(
# Case-insensitive substring search on UTF-8 payload (stored as BLOB)
if contains:
contains_lower = contains.lower()
conditions.append(
func.lower(models.Packet.payload).like(f"%{contains_lower}%")
)
conditions.append(func.lower(models.Packet.payload).like(f"%{contains_lower}%"))
# Apply all conditions
if conditions:
@@ -386,22 +380,18 @@ async def get_channels_in_period(period_type: str = "hour", length: int = 24):
async with database.async_session() as session:
stmt = (
select(Packet.channel)
.where(Packet.import_time_us >= start_us)
.distinct()
.order_by(Packet.channel)
.where(Packet.import_time_us >= start_us)
.distinct()
.order_by(Packet.channel)
)
result = await session.execute(stmt)
channels = [
ch for ch in result.scalars().all()
if ch is not None
]
channels = [ch for ch in result.scalars().all() if ch is not None]
return channels
async def get_total_packet_count(
period_type: str | None = None,
length: int | None = None,

View File

@@ -193,6 +193,7 @@ async def index(request):
starting_url = CONFIG["site"].get("starting", "/map") # default to /map if not set
raise web.HTTPFound(location=starting_url)
# redirect for backwards compatibility
@routes.get("/packet_list/{packet_id}")
async def redirect_packet_list(request):
@@ -275,6 +276,7 @@ async def top(request):
content_type="text/html",
)
@routes.get("/stats")
async def stats(request):
template = env.get_template("stats.html")
@@ -391,6 +393,7 @@ async def graph_traceroute(request):
content_type="image/svg+xml",
)
'''
@routes.get("/stats")
async def stats(request):
@@ -415,6 +418,7 @@ async def stats(request):
)
'''
async def run_server():
# Wait for database migrations to complete before starting web server
logger.info("Checking database schema status...")

View File

@@ -103,8 +103,8 @@ async def api_packets(request):
# NEW — explicit filters
from_node_id_str = request.query.get("from_node_id")
to_node_id_str = request.query.get("to_node_id")
node_id_str = request.query.get("node_id") # legacy: match either from/to
to_node_id_str = request.query.get("to_node_id")
node_id_str = request.query.get("node_id") # legacy: match either from/to
# --- If a packet_id is provided, return only that packet ---
if packet_id_str:
@@ -197,8 +197,7 @@ async def api_packets(request):
# --- Sort descending by import_time_us ---
ui_packets.sort(
key=lambda p: (p.import_time_us is not None, p.import_time_us or 0),
reverse=True
key=lambda p: (p.import_time_us is not None, p.import_time_us or 0), reverse=True
)
ui_packets = ui_packets[:limit]
@@ -253,7 +252,6 @@ async def api_packets(request):
return web.json_response({"error": "Failed to fetch packets"}, status=500)
@routes.get("/api/stats")
async def api_stats(request):
"""