Merge remote-tracking branch 'forgejo/master'
Some checks failed
build-and-deploy / build (push) Failing after 4s

# Conflicts:
#	.env.example
This commit is contained in:
Sirius DevOps 2026-08-24 15:40:31 -04:00
commit cf98af8101
8 changed files with 735 additions and 7 deletions

View file

@ -696,6 +696,77 @@ async def sentiment_by_source(hours: int = 24):
} for r in rows]
# ── Cameras (open-camera discovery map) ───────────────────────────────────
@app.get("/api/cameras")
async def list_cameras(
bbox: str | None = Query(
None,
description="Bounding box 'min_lon,min_lat,max_lon,max_lat'",
),
source: str | None = Query(None, description="Filter by discovery_source"),
limit: int = Query(500, ge=1, le=5000),
):
"""Cameras for map display, optionally filtered by geographic bbox."""
from camera_models import cameras as cam_table
async with async_session() as session:
stmt = select(cam_table).order_by(cam_table.c.last_seen.desc())
if bbox:
try:
min_lon, min_lat, max_lon, max_lat = (
float(v) for v in bbox.split(",")
)
except ValueError:
raise HTTPException(
422, "bbox must be 'min_lon,min_lat,max_lon,max_lat'"
)
if not (-180 <= min_lon <= 180 and -180 <= max_lon <= 180
and -90 <= min_lat <= 90 and -90 <= max_lat <= 90):
raise HTTPException(422, "bbox coordinates out of range")
stmt = stmt.where(
and_(cam_table.c.location_lat >= min_lat,
cam_table.c.location_lat <= max_lat,
cam_table.c.location_lon >= min_lon,
cam_table.c.location_lon <= max_lon))
if source:
stmt = stmt.where(cam_table.c.discovery_source == source)
rows = (await session.execute(stmt.limit(limit))).mappings().all()
return [{
"id": str(r["id"]),
"source_url": r["source_url"],
"snapshot_url": r["snapshot_url"],
"discovery_source": r["discovery_source"],
"lat": r["location_lat"],
"lon": r["location_lon"],
"location_name": r["location_name"],
"vendor": r["vendor"],
"device_type": r["device_type"],
"first_seen": r["first_seen"].isoformat(),
"last_seen": r["last_seen"].isoformat(),
} for r in rows]
@app.get("/api/cameras/{camera_id}/snapshot")
async def camera_snapshot(camera_id: UUID):
"""Snapshot image for one camera, served through the local TTL cache."""
from camera_models import cameras as cam_table
from camera_scraper import fetch_snapshot
async with async_session() as session:
row = (await session.execute(
select(cam_table).where(cam_table.c.id == camera_id)
)).mappings().one_or_none()
if not row or not row["snapshot_url"]:
raise HTTPException(404, "Camera or snapshot not found")
data = await fetch_snapshot(row["snapshot_url"])
if not data:
raise HTTPException(502, "Snapshot unavailable")
from fastapi.responses import Response
return Response(content=data, media_type="image/jpeg")
# ── Frontend ──────────────────────────────────────────────────────────────
@app.get("/", response_class=HTMLResponse)