mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-24 06:17:12 +03:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84c678d03e | ||
|
|
61acbb2dcd |
@@ -41,9 +41,6 @@ def swap_runtime_config(app: FastAPI, config: FrigateConfig) -> None:
|
||||
"""
|
||||
app.frigate_config = config
|
||||
|
||||
if app.replay_manager is not None:
|
||||
app.replay_manager.update_config(config)
|
||||
|
||||
if app.config_holder is not None:
|
||||
app.config_holder.set(config)
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ def create_fastapi_app(
|
||||
logger.info("FastAPI started")
|
||||
asyncio.create_task(
|
||||
debug_replay_auto_stop_watchdog(
|
||||
replay_manager, lambda: app.frigate_config, config_publisher
|
||||
replay_manager, frigate_config, config_publisher
|
||||
)
|
||||
)
|
||||
yield
|
||||
|
||||
@@ -20,7 +20,7 @@ from urllib.parse import unquote
|
||||
from peewee import DoesNotExist, Field
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import CLIPS_DIR, EXPORT_DIR
|
||||
from frigate.const import CLIPS_DIR, EXPORT_DIR, SUB_CACHE_TAG
|
||||
from frigate.models import Export, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -137,11 +137,12 @@ def _resolve_recording(
|
||||
# /recordings/{date} → neutral
|
||||
# /recordings/{date}/{hour} → multi-camera listing
|
||||
# /recordings/{date}/{hour}/{cam}/... → camera
|
||||
# /recordings/{date}/{hour}/{cam}@sub/... → camera (sub stream)
|
||||
if len(parts) <= 2:
|
||||
return MediaAuthResolution.LISTING_NEUTRAL, None
|
||||
if len(parts) == 3:
|
||||
return MediaAuthResolution.LISTING_MULTI_CAMERA, None
|
||||
return MediaAuthResolution.CAMERA, parts[3]
|
||||
return MediaAuthResolution.CAMERA, parts[3].removesuffix(SUB_CACHE_TAG)
|
||||
|
||||
|
||||
def _resolve_clip(
|
||||
@@ -150,6 +151,7 @@ def _resolve_clip(
|
||||
# /clips → multi-camera listing
|
||||
# /clips/thumbs/{cam}/... → camera
|
||||
# /clips/previews/{cam}/... → camera
|
||||
# /clips/triggers/{cam}/... → camera
|
||||
# /clips/review/thumb-{cam}-{review_id}.webp → camera (parsed)
|
||||
# /clips/export/{export_id}.{ext} → camera (DB lookup)
|
||||
# /clips/faces/... → admin-only
|
||||
@@ -163,7 +165,7 @@ def _resolve_clip(
|
||||
|
||||
second = parts[1]
|
||||
|
||||
if second in ("thumbs", "previews"):
|
||||
if second in ("thumbs", "previews", "triggers"):
|
||||
if len(parts) == 2:
|
||||
return MediaAuthResolution.LISTING_MULTI_CAMERA, None
|
||||
return MediaAuthResolution.CAMERA, parts[2]
|
||||
|
||||
@@ -685,7 +685,7 @@ class WebPushClient(Communicator):
|
||||
|
||||
title = f"{name.replace('_', ' ')} triggered on {camera_name}"
|
||||
message = f"{titlecase(trigger_type)} trigger fired for {camera_name} with score {score:.2f}"
|
||||
image = f"clips/triggers/{camera}/{event_id}.webp"
|
||||
image = f"api/events/{event_id}/thumbnail.webp"
|
||||
|
||||
direct_url = f"/explore?event_id={event_id}"
|
||||
ttl = 0
|
||||
|
||||
+14
-31
@@ -11,11 +11,10 @@ import os
|
||||
import shutil
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
from frigate.config import CameraConfig, FrigateConfig
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
CameraConfigUpdatePublisher,
|
||||
@@ -62,7 +61,6 @@ class DebugReplayManager:
|
||||
self.start_ts: float | None = None
|
||||
self.end_ts: float | None = None
|
||||
self.session_started_at: float | None = None
|
||||
self._published_camera: CameraConfig | None = None
|
||||
self._job_state_publisher = JobStatePublisher()
|
||||
|
||||
@property
|
||||
@@ -111,13 +109,6 @@ class DebugReplayManager:
|
||||
self.start_ts = None
|
||||
self.end_ts = None
|
||||
self.session_started_at = None
|
||||
self._published_camera = None
|
||||
|
||||
def update_config(self, config: FrigateConfig) -> None:
|
||||
"""Carry the published replay camera into a newly swapped-in config."""
|
||||
with self._lock:
|
||||
if self._published_camera is not None and self.replay_camera_name:
|
||||
config.cameras[self.replay_camera_name] = self._published_camera
|
||||
|
||||
def publish_camera(
|
||||
self,
|
||||
@@ -126,11 +117,10 @@ class DebugReplayManager:
|
||||
clip_path: str,
|
||||
frigate_config: FrigateConfig,
|
||||
config_publisher: CameraConfigUpdatePublisher,
|
||||
) -> bool:
|
||||
) -> None:
|
||||
"""Build the in-memory replay camera config and publish the add event.
|
||||
|
||||
Called by the job runner during the starting_camera phase. Returns
|
||||
False without publishing if the session was stopped meanwhile.
|
||||
Called by the job runner during the starting_camera phase.
|
||||
"""
|
||||
source_config = frigate_config.cameras[source_camera]
|
||||
camera_dict = self._build_camera_config_dict(
|
||||
@@ -150,21 +140,12 @@ class DebugReplayManager:
|
||||
new_config = FrigateConfig.parse_object(config_data)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to validate replay camera config: {e}") from e
|
||||
frigate_config.cameras[replay_name] = new_config.cameras[replay_name]
|
||||
|
||||
camera_config = new_config.cameras[replay_name]
|
||||
|
||||
with self._lock:
|
||||
if self.replay_camera_name != replay_name:
|
||||
return False
|
||||
|
||||
frigate_config.cameras[replay_name] = camera_config
|
||||
self._published_camera = camera_config
|
||||
config_publisher.publish_update(
|
||||
CameraConfigUpdateTopic(CameraConfigUpdateEnum.add, replay_name),
|
||||
camera_config,
|
||||
)
|
||||
|
||||
return True
|
||||
config_publisher.publish_update(
|
||||
CameraConfigUpdateTopic(CameraConfigUpdateEnum.add, replay_name),
|
||||
new_config.cameras[replay_name],
|
||||
)
|
||||
|
||||
def stop(
|
||||
self,
|
||||
@@ -186,10 +167,12 @@ class DebugReplayManager:
|
||||
replay_name = self.replay_camera_name
|
||||
source_camera = self.source_camera
|
||||
|
||||
if replay_name is not None and self._published_camera is not None:
|
||||
# Only publish remove if the camera was actually added to the live
|
||||
# config (i.e. the runner reached the starting_camera phase).
|
||||
if replay_name is not None and replay_name in frigate_config.cameras:
|
||||
config_publisher.publish_update(
|
||||
CameraConfigUpdateTopic(CameraConfigUpdateEnum.remove, replay_name),
|
||||
self._published_camera,
|
||||
frigate_config.cameras[replay_name],
|
||||
)
|
||||
frigate_config.cameras.pop(replay_name, None)
|
||||
|
||||
@@ -379,7 +362,7 @@ def cleanup_replay_cameras() -> None:
|
||||
|
||||
async def debug_replay_auto_stop_watchdog(
|
||||
manager: DebugReplayManager,
|
||||
get_config: Callable[[], FrigateConfig],
|
||||
frigate_config: FrigateConfig,
|
||||
config_publisher: CameraConfigUpdatePublisher,
|
||||
) -> None:
|
||||
"""Auto-stop debug replay sessions that exceed MAX_SESSION_DURATION_SECONDS.
|
||||
@@ -401,7 +384,7 @@ async def debug_replay_auto_stop_watchdog(
|
||||
replay_name = manager.replay_camera_name
|
||||
await asyncio.to_thread(
|
||||
manager.stop,
|
||||
frigate_config=get_config(),
|
||||
frigate_config=frigate_config,
|
||||
config_publisher=config_publisher,
|
||||
)
|
||||
logger.info(
|
||||
|
||||
@@ -376,16 +376,13 @@ class DebugReplayJobRunner(threading.Thread):
|
||||
self._finalize_cancelled(clip_path)
|
||||
return
|
||||
|
||||
if not self.replay_manager.publish_camera(
|
||||
self.replay_manager.publish_camera(
|
||||
source_camera=self.job.source_camera,
|
||||
replay_name=replay_name,
|
||||
clip_path=clip_path,
|
||||
frigate_config=self.frigate_config,
|
||||
config_publisher=self.config_publisher,
|
||||
):
|
||||
self._finalize_cancelled(clip_path)
|
||||
return
|
||||
|
||||
)
|
||||
self.replay_manager.mark_session_ready(clip_path)
|
||||
|
||||
self.job.status = JobStatusTypesEnum.success
|
||||
|
||||
@@ -487,9 +487,6 @@ def get_export_job_manager(config: FrigateConfig) -> ExportJobManager:
|
||||
with _job_manager_lock:
|
||||
if _job_manager is None:
|
||||
_job_manager = ExportJobManager(config, _get_max_concurrent(config))
|
||||
|
||||
# callers pass the live config, which a save replaces
|
||||
_job_manager.config = config
|
||||
_job_manager.ensure_started()
|
||||
return _job_manager
|
||||
|
||||
|
||||
+10
-14
@@ -789,16 +789,16 @@ class BirdsEyeFrameManager:
|
||||
force_update = True
|
||||
else:
|
||||
return False, False
|
||||
else:
|
||||
# update the last active frame for the camera
|
||||
camera_state["current_frame"] = frame.copy()
|
||||
camera_state["current_frame_time"] = frame_time
|
||||
modes = camera_config.birdseye.modes
|
||||
|
||||
if self.camera_threshold_active(modes, activity):
|
||||
camera_state["last_active_frame"] = frame_time
|
||||
# update the last active frame for the camera
|
||||
camera_state["current_frame"] = frame.copy()
|
||||
camera_state["current_frame_time"] = frame_time
|
||||
modes = camera_config.birdseye.modes
|
||||
|
||||
camera_state["live_active"] = self.camera_live_active(modes, activity)
|
||||
if self.camera_threshold_active(modes, activity):
|
||||
camera_state["last_active_frame"] = frame_time
|
||||
|
||||
camera_state["live_active"] = self.camera_live_active(modes, activity)
|
||||
|
||||
# monotonic so a backward wall clock step can't freeze the output
|
||||
now = time.monotonic()
|
||||
@@ -865,10 +865,7 @@ class Birdseye:
|
||||
(1.0 / self.idle_fps) if self.idle_fps > 0 else None
|
||||
)
|
||||
|
||||
# restream changes need a restart, so the buffer exists only if it did at init
|
||||
self.restream = config.birdseye.restream
|
||||
|
||||
if self.restream:
|
||||
if config.birdseye.restream:
|
||||
self.birdseye_buffer: Any = self.frame_manager.create(
|
||||
"birdseye",
|
||||
self.birdseye_manager.yuv_shape[0] * self.birdseye_manager.yuv_shape[1],
|
||||
@@ -880,7 +877,7 @@ class Birdseye:
|
||||
def __send_new_frame(self) -> None:
|
||||
frame_bytes = self.birdseye_manager.frame.tobytes()
|
||||
|
||||
if self.restream:
|
||||
if self.config.birdseye.restream:
|
||||
self.birdseye_buffer[:] = frame_bytes
|
||||
|
||||
try:
|
||||
@@ -957,7 +954,6 @@ class Birdseye:
|
||||
>= self._idle_interval
|
||||
):
|
||||
self.__send_new_frame()
|
||||
self.birdseye_manager.last_output_time = now
|
||||
|
||||
def stop(self) -> None:
|
||||
self.review_subscriber.stop()
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
import multiprocessing as mp
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import numpy as np
|
||||
from unittest.mock import Mock
|
||||
|
||||
from frigate.config import (
|
||||
BirdseyeModeEnum,
|
||||
@@ -609,72 +607,6 @@ class TestBirdseyeModePayload(unittest.TestCase):
|
||||
assert birdseye_modes_from_mqtt_payload(payload) is None
|
||||
|
||||
|
||||
class TestBirdseyeRuntimeToggles(unittest.TestCase):
|
||||
"""Runtime config changes must not crash or overdrive Birdseye."""
|
||||
|
||||
def setUp(self):
|
||||
config = {
|
||||
"mqtt": {"enabled": False},
|
||||
"birdseye": {"enabled": True, "modes": ["continuous"]},
|
||||
"cameras": {
|
||||
"front": {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
|
||||
]
|
||||
},
|
||||
"detect": {"height": 1080, "width": 1920, "fps": 5},
|
||||
}
|
||||
},
|
||||
}
|
||||
self.config = FrigateConfig(**config)
|
||||
self.manager = BirdsEyeFrameManager(self.config, mp.Event())
|
||||
self.frame = np.zeros((1620, 1920), np.uint8)
|
||||
self.activity = BirdseyeActivity(
|
||||
has_object=True, has_motion=True, severity=None
|
||||
)
|
||||
|
||||
def test_disabled_camera_forces_one_update_only(self):
|
||||
self.manager.update("front", self.activity, 1000.0, self.frame)
|
||||
self.config.cameras["front"].birdseye.enabled = False
|
||||
|
||||
changed, _ = self.manager.update("front", self.activity, 1000.2, self.frame)
|
||||
assert changed
|
||||
|
||||
changed, _ = self.manager.update("front", self.activity, 1000.4, self.frame)
|
||||
assert not changed
|
||||
|
||||
def test_enabling_restream_at_runtime_does_not_write_missing_buffer(self):
|
||||
birdseye = Birdseye.__new__(Birdseye)
|
||||
birdseye.restream = False
|
||||
birdseye.config = self.config
|
||||
birdseye.birdseye_manager = self.manager
|
||||
birdseye.input = Mock()
|
||||
self.config.birdseye.restream = True
|
||||
|
||||
birdseye._Birdseye__send_new_frame()
|
||||
|
||||
birdseye.input.put_nowait.assert_called_once()
|
||||
|
||||
def test_idle_heartbeat_waits_a_full_interval_between_sends(self):
|
||||
birdseye = Birdseye.__new__(Birdseye)
|
||||
birdseye.review_severity = {}
|
||||
birdseye.birdseye_manager = Mock()
|
||||
birdseye.birdseye_manager.update.return_value = (False, False)
|
||||
birdseye.birdseye_manager.camera_layout = []
|
||||
birdseye.birdseye_manager.last_output_time = 0.0
|
||||
birdseye._idle_interval = 0.2
|
||||
|
||||
with (
|
||||
patch.object(Birdseye, "_Birdseye__send_new_frame") as send,
|
||||
patch("frigate.output.birdseye.time.monotonic", side_effect=[10.0, 10.1]),
|
||||
):
|
||||
birdseye.write_data("front", [], [], 1.0, Mock())
|
||||
birdseye.write_data("front", [], [], 1.1, Mock())
|
||||
|
||||
assert send.call_count == 1
|
||||
|
||||
|
||||
class TestBirdseyeReviewSeverity(unittest.TestCase):
|
||||
"""Test that review updates drive the per-camera severity map."""
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ class TestSwapRuntimeConfig(unittest.TestCase):
|
||||
|
||||
self.assertIs(app.frigate_config, config)
|
||||
app.genai_manager.update_config.assert_called_once_with(config)
|
||||
app.replay_manager.update_config.assert_called_once_with(config)
|
||||
app.profile_manager.update_config.assert_called_once_with(config)
|
||||
self.assertIs(app.stats_emitter.config, config)
|
||||
app.stats_emitter.hardware_stats.set_config.assert_called_once_with(config)
|
||||
|
||||
@@ -101,7 +101,6 @@ class TestDebugReplayManagerStop(unittest.TestCase):
|
||||
manager.mark_session_ready("/tmp/replay/_replay_front.mp4")
|
||||
|
||||
camera_config = MagicMock()
|
||||
manager._published_camera = camera_config
|
||||
frigate_config = MagicMock()
|
||||
frigate_config.cameras = {"_replay_front": camera_config}
|
||||
publisher = MagicMock()
|
||||
@@ -170,7 +169,6 @@ class TestDebugReplayManagerPublishCamera(unittest.TestCase):
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
manager = DebugReplayManager()
|
||||
manager.mark_starting("front", "_replay_front", 100.0, 200.0)
|
||||
|
||||
source_config = MagicMock()
|
||||
new_camera_config = MagicMock()
|
||||
@@ -248,103 +246,5 @@ class TestDebugReplayManagerPublishCamera(unittest.TestCase):
|
||||
publisher.publish_update.assert_not_called()
|
||||
|
||||
|
||||
class TestDebugReplayManagerLifecycle(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
patcher = patch("frigate.debug_replay.JobStatePublisher")
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def _publish(self, manager, frigate_config, publisher) -> bool:
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
parsed = MagicMock()
|
||||
parsed.cameras = {"_replay_front": MagicMock(name="replay_camera")}
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
DebugReplayManager,
|
||||
"_build_camera_config_dict",
|
||||
return_value={"enabled": True},
|
||||
),
|
||||
patch("frigate.debug_replay.find_config_file", return_value="/cfg.yml"),
|
||||
patch("frigate.debug_replay.YAML") as yaml_cls,
|
||||
patch(
|
||||
"frigate.debug_replay.FrigateConfig.parse_object",
|
||||
return_value=parsed,
|
||||
),
|
||||
patch("builtins.open", unittest.mock.mock_open(read_data="cameras:\n")),
|
||||
):
|
||||
yaml_cls.return_value.load.return_value = {"cameras": {}}
|
||||
return manager.publish_camera(
|
||||
source_camera="front",
|
||||
replay_name="_replay_front",
|
||||
clip_path="/tmp/clip.mp4",
|
||||
frigate_config=frigate_config,
|
||||
config_publisher=publisher,
|
||||
)
|
||||
|
||||
def _config(self, name: str) -> MagicMock:
|
||||
config = MagicMock(name=name)
|
||||
config.cameras = {"front": MagicMock()}
|
||||
return config
|
||||
|
||||
def _stop(self, manager, frigate_config, publisher) -> None:
|
||||
with (
|
||||
patch.object(manager, "_cleanup_db"),
|
||||
patch.object(manager, "_cleanup_files"),
|
||||
patch("frigate.debug_replay.cancel_debug_replay_job", return_value=False),
|
||||
):
|
||||
manager.stop(frigate_config=frigate_config, config_publisher=publisher)
|
||||
|
||||
def test_publish_after_stop_is_skipped(self) -> None:
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
manager = DebugReplayManager()
|
||||
manager.mark_starting("front", "_replay_front", 100.0, 200.0)
|
||||
config = self._config("live")
|
||||
publisher = MagicMock()
|
||||
|
||||
self._stop(manager, config, publisher)
|
||||
|
||||
self.assertFalse(self._publish(manager, config, publisher))
|
||||
self.assertNotIn("_replay_front", config.cameras)
|
||||
publisher.publish_update.assert_not_called()
|
||||
|
||||
def test_config_swap_keeps_replay_camera_and_stop_removes_it(self) -> None:
|
||||
from frigate.config.camera.updater import CameraConfigUpdateEnum
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
manager = DebugReplayManager()
|
||||
manager.mark_starting("front", "_replay_front", 100.0, 200.0)
|
||||
boot = self._config("boot")
|
||||
publisher = MagicMock()
|
||||
self.assertTrue(self._publish(manager, boot, publisher))
|
||||
|
||||
swapped = self._config("swapped")
|
||||
manager.update_config(swapped)
|
||||
self.assertIn("_replay_front", swapped.cameras)
|
||||
|
||||
self._stop(manager, swapped, publisher)
|
||||
|
||||
topic = publisher.publish_update.call_args.args[0]
|
||||
self.assertEqual(topic.update_type, CameraConfigUpdateEnum.remove)
|
||||
self.assertNotIn("_replay_front", swapped.cameras)
|
||||
|
||||
def test_stop_with_stale_config_still_publishes_remove(self) -> None:
|
||||
from frigate.config.camera.updater import CameraConfigUpdateEnum
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
manager = DebugReplayManager()
|
||||
manager.mark_starting("front", "_replay_front", 100.0, 200.0)
|
||||
live = self._config("live")
|
||||
publisher = MagicMock()
|
||||
self.assertTrue(self._publish(manager, live, publisher))
|
||||
|
||||
self._stop(manager, self._config("stale"), publisher)
|
||||
|
||||
topic = publisher.publish_update.call_args.args[0]
|
||||
self.assertEqual(topic.update_type, CameraConfigUpdateEnum.remove)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -302,7 +302,7 @@ class TestRunnerHappyPath(unittest.TestCase):
|
||||
patch.object(
|
||||
self.manager,
|
||||
"publish_camera",
|
||||
side_effect=lambda *a, **kw: captured.append("published") or True,
|
||||
side_effect=lambda *a, **kw: captured.append("published"),
|
||||
),
|
||||
patch("os.path.exists", return_value=True),
|
||||
patch("os.makedirs"),
|
||||
|
||||
@@ -221,24 +221,6 @@ class TestFfmpegProgressParsing(unittest.TestCase):
|
||||
assert any(abs(p - (30 / 90 * 100)) < 0.01 for p in encoding_percents)
|
||||
|
||||
|
||||
class TestExportJobManagerConfig(unittest.TestCase):
|
||||
def test_manager_follows_the_config_passed_by_callers(self) -> None:
|
||||
import frigate.jobs.export as export_jobs
|
||||
|
||||
boot = MagicMock(name="boot")
|
||||
swapped = MagicMock(name="swapped")
|
||||
|
||||
with (
|
||||
patch.object(export_jobs, "_job_manager", None),
|
||||
patch.object(export_jobs.ExportJobManager, "ensure_started"),
|
||||
patch.object(export_jobs, "_get_max_concurrent", return_value=1),
|
||||
):
|
||||
export_jobs.get_export_job_manager(boot)
|
||||
manager = export_jobs.get_export_job_manager(swapped)
|
||||
|
||||
self.assertIs(manager.config, swapped)
|
||||
|
||||
|
||||
class TestBroadcastAggregation(unittest.TestCase):
|
||||
"""Verify ExportJobManager broadcast payload shape and throttling."""
|
||||
|
||||
|
||||
@@ -122,6 +122,11 @@ class TestResolveMediaUri(unittest.TestCase):
|
||||
MediaAuthResolution.CAMERA,
|
||||
camera="back_door",
|
||||
)
|
||||
self._assert(
|
||||
"/recordings/2026-05-11/14/back_door@sub/00.00.mp4",
|
||||
MediaAuthResolution.CAMERA,
|
||||
camera="back_door",
|
||||
)
|
||||
|
||||
def test_clip_flat_filename_resolves_camera(self):
|
||||
self._assert(
|
||||
@@ -177,6 +182,14 @@ class TestResolveMediaUri(unittest.TestCase):
|
||||
camera="back_door",
|
||||
)
|
||||
|
||||
def test_clip_triggers(self):
|
||||
self._assert("/clips/triggers/", MediaAuthResolution.LISTING_MULTI_CAMERA)
|
||||
self._assert(
|
||||
"/clips/triggers/back_door/abc.webp",
|
||||
MediaAuthResolution.CAMERA,
|
||||
camera="back_door",
|
||||
)
|
||||
|
||||
def test_clip_review_thumbs(self):
|
||||
# Format: /clips/review/thumb-{camera}-{review_id}.webp (frigate/review/maintainer.py).
|
||||
self._assert(
|
||||
@@ -340,6 +353,14 @@ class TestDenyResponseForMediaUri(unittest.TestCase):
|
||||
self.assertIsNone(
|
||||
self._deny("/clips/thumbs/front_door/abc.webp", "limited_user")
|
||||
)
|
||||
self.assertIsNone(
|
||||
self._deny(
|
||||
"/recordings/2026-05-11/14/front_door@sub/00.00.mp4", "limited_user"
|
||||
)
|
||||
)
|
||||
self.assertIsNone(
|
||||
self._deny("/clips/triggers/front_door/abc.webp", "limited_user")
|
||||
)
|
||||
|
||||
def test_restricted_role_blocked_other_camera(self):
|
||||
self.assertEqual(self._deny("/clips/back_door-1.jpg", "limited_user"), 403)
|
||||
@@ -350,6 +371,15 @@ class TestDenyResponseForMediaUri(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
self._deny("/clips/thumbs/back_door/abc.webp", "limited_user"), 403
|
||||
)
|
||||
self.assertEqual(
|
||||
self._deny(
|
||||
"/recordings/2026-05-11/14/back_door@sub/00.00.mp4", "limited_user"
|
||||
),
|
||||
403,
|
||||
)
|
||||
self.assertEqual(
|
||||
self._deny("/clips/triggers/back_door/abc.webp", "limited_user"), 403
|
||||
)
|
||||
|
||||
def test_restricted_role_blocked_admin_only(self):
|
||||
self.assertEqual(self._deny("/clips/faces/train/foo.webp", "limited_user"), 403)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Tests for media sync orphan cleanup."""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from peewee import SqliteDatabase
|
||||
|
||||
from frigate.models import Export, ExportCase
|
||||
from frigate.util.media import sync_exports
|
||||
|
||||
|
||||
class TestSyncExports(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.db = SqliteDatabase(":memory:")
|
||||
self.enterContext(self.db.bind_ctx([Export, ExportCase]))
|
||||
self.db.create_tables([Export, ExportCase])
|
||||
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.clips_dir = os.path.join(self.tmp.name, "clips")
|
||||
self.export_dir = os.path.join(self.tmp.name, "exports")
|
||||
self.thumb_dir = os.path.join(self.clips_dir, "export")
|
||||
os.makedirs(self.thumb_dir)
|
||||
os.makedirs(self.export_dir)
|
||||
|
||||
patcher_clips = patch("frigate.util.media.CLIPS_DIR", self.clips_dir)
|
||||
patcher_exports = patch("frigate.util.media.EXPORT_DIR", self.export_dir)
|
||||
patcher_clips.start()
|
||||
patcher_exports.start()
|
||||
self.addCleanup(patcher_clips.stop)
|
||||
self.addCleanup(patcher_exports.stop)
|
||||
|
||||
def tearDown(self):
|
||||
self.db.close()
|
||||
self.tmp.cleanup()
|
||||
|
||||
def _touch(self, path: str) -> str:
|
||||
open(path, "wb").close()
|
||||
return path
|
||||
|
||||
def test_orphaned_webp_and_jpg_thumbnails_are_removed(self):
|
||||
for i, ext in enumerate(("webp", "jpg")):
|
||||
Export.insert(
|
||||
id=f"front_{i}",
|
||||
camera="front",
|
||||
name=f"export {i}",
|
||||
date=0,
|
||||
video_path=self._touch(os.path.join(self.export_dir, f"{i}.mp4")),
|
||||
thumb_path=self._touch(os.path.join(self.thumb_dir, f"{i}.{ext}")),
|
||||
in_progress=False,
|
||||
).execute()
|
||||
|
||||
orphan_webp = self._touch(os.path.join(self.thumb_dir, "gone.webp"))
|
||||
orphan_jpg = self._touch(os.path.join(self.thumb_dir, "gone.jpg"))
|
||||
|
||||
result = sync_exports()
|
||||
|
||||
self.assertEqual(sorted(result.orphan_paths), sorted([orphan_jpg, orphan_webp]))
|
||||
self.assertEqual(result.orphans_deleted, 2)
|
||||
self.assertEqual(sorted(os.listdir(self.thumb_dir)), ["0.webp", "1.jpg"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Tests for trigger push notifications."""
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from frigate.comms.webpush import WebPushClient
|
||||
|
||||
|
||||
class TestTriggerNotification(unittest.TestCase):
|
||||
def test_image_is_the_triggering_event_thumbnail(self):
|
||||
client = WebPushClient.__new__(WebPushClient)
|
||||
client.config = SimpleNamespace(
|
||||
notifications=SimpleNamespace(email="admin@example.com"),
|
||||
cameras={"front_door": SimpleNamespace(friendly_name=None)},
|
||||
)
|
||||
client.web_pushers = {"admin": []}
|
||||
client.user_cameras = {"admin": {"front_door"}}
|
||||
client.last_camera_notification_time = {}
|
||||
client._within_cooldown = MagicMock(return_value=False)
|
||||
client.check_registrations = MagicMock()
|
||||
client.cleanup_registrations = MagicMock()
|
||||
client.send_push_notification = MagicMock()
|
||||
|
||||
client.send_trigger(
|
||||
{
|
||||
"camera": "front_door",
|
||||
"event_id": "1700000000.0-abc123",
|
||||
"name": "red_car",
|
||||
"type": "thumbnail",
|
||||
"score": 0.9,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
client.send_push_notification.call_args.kwargs["image"],
|
||||
"api/events/1700000000.0-abc123/thumbnail.webp",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -639,7 +639,7 @@ def sync_exports(dry_run: bool = False, force: bool = False) -> SyncResult:
|
||||
"""Sync export files - delete files not referenced by any export record.
|
||||
|
||||
Export videos are stored at: EXPORT_DIR/*.mp4
|
||||
Export thumbnails are stored at: CLIPS_DIR/export/*.jpg
|
||||
Export thumbnails are stored at: CLIPS_DIR/export/*.webp (legacy *.jpg)
|
||||
The paths are stored in Export.video_path and Export.thumb_path
|
||||
"""
|
||||
result = SyncResult(media_type="exports")
|
||||
@@ -667,7 +667,7 @@ def sync_exports(dry_run: bool = False, force: bool = False) -> SyncResult:
|
||||
thumb_files: list[str] = []
|
||||
if os.path.isdir(export_thumb_dir):
|
||||
for file in os.listdir(export_thumb_dir):
|
||||
if file.endswith(".jpg"):
|
||||
if file.endswith((".webp", ".jpg")):
|
||||
file_path = os.path.join(export_thumb_dir, file)
|
||||
thumb_files.append(file_path)
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ export function processCameraName(userInput: string): {
|
||||
} {
|
||||
const normalizedInput = userInput.replace(/\s+/g, "_").toLowerCase();
|
||||
|
||||
// debug replay owns this prefix and deletes data for cameras that use it
|
||||
if (isValidId(normalizedInput) && !isReplayCamera(normalizedInput)) {
|
||||
if (isValidId(normalizedInput)) {
|
||||
return {
|
||||
finalCameraName: normalizedInput,
|
||||
friendlyName: userInput.includes(" ") ? userInput : undefined,
|
||||
|
||||
Reference in New Issue
Block a user