cameras: surface per-camera REC (record-to-disk) toggle
`enabled` already gated recording only (go2rtc/live work regardless), but
it was a buried "Вкл" checkbox. Make it an explicit REC control:
- New "Запись" column with an inline REC switch in each camera row.
- Relabel the add/edit form toggle "Вкл" -> "REC" + tooltip.
- New POST /api/cameras/{id}/record {enabled} that flips recording through
the supervisor only (no go2rtc re-sync, so live view doesn't blip).
Off = view-only (live via go2rtc); on = record segments to disk.
VERSION -> 0.0.124.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
from dataclasses import replace
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query, Request, WebSocket, WebSocketDisconnect
|
||||
from fastapi.responses import StreamingResponse
|
||||
@@ -298,3 +299,23 @@ async def clear_cameras(request: Request) -> dict:
|
||||
await runtime.supervisor.remove_camera(cam_id)
|
||||
await go2rtc.remove_camera_streams(runtime.config, cam_id)
|
||||
return {"ok": True, "removed": len(ids)}
|
||||
|
||||
|
||||
@router.post("/{cam_id}/record")
|
||||
async def set_record(cam_id: str, request: Request) -> dict:
|
||||
"""Включает/выключает запись камеры на диск (тумблер REC).
|
||||
|
||||
enabled=False — запись не идёт, но go2rtc/live не трогаем → просмотр работает.
|
||||
Меняет только рекордер (без пересоздания go2rtc-потоков, чтобы live не мигал)."""
|
||||
require_role(request, "admin")
|
||||
cam = runtime.config.camera(cam_id)
|
||||
if not cam:
|
||||
raise HTTPException(404, "camera not found")
|
||||
body = await request.json()
|
||||
on = bool(body.get("enabled", True))
|
||||
idx = next(i for i, c in enumerate(runtime.config.cameras) if c.id == cam_id)
|
||||
new = replace(cam, enabled=on)
|
||||
runtime.config.cameras[idx] = new
|
||||
save_config(runtime.config)
|
||||
await runtime.supervisor.replace_camera(new) # старт/стоп записи; go2rtc не трогаем
|
||||
return {"ok": True, "enabled": on}
|
||||
|
||||
Reference in New Issue
Block a user