mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-21 04:53:02 +03:00
Compare commits
1
Commits
dev
..
heic-handling
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
130815ac70 |
@@ -17,10 +17,10 @@ import re
|
||||
from enum import Enum
|
||||
from urllib.parse import unquote
|
||||
|
||||
from peewee import DoesNotExist, Field
|
||||
from peewee import DoesNotExist
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import CLIPS_DIR, EXPORT_DIR
|
||||
from frigate.const import EXPORT_DIR
|
||||
from frigate.models import Export, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -151,7 +151,6 @@ def _resolve_clip(
|
||||
# /clips/thumbs/{cam}/... → camera
|
||||
# /clips/previews/{cam}/... → camera
|
||||
# /clips/review/thumb-{cam}-{review_id}.webp → camera (parsed)
|
||||
# /clips/export/{export_id}.{ext} → camera (DB lookup)
|
||||
# /clips/faces/... → admin-only
|
||||
# /clips/genai-requests/... → admin-only
|
||||
# /clips/preview_restart_cache/... → admin-only
|
||||
@@ -176,11 +175,6 @@ def _resolve_clip(
|
||||
return MediaAuthResolution.CAMERA, camera
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
if second == "export" and len(parts) == 3:
|
||||
return _export_camera(
|
||||
Export.thumb_path, os.path.join(CLIPS_DIR, "export", parts[2])
|
||||
)
|
||||
|
||||
if second in ("faces", "genai-requests", "preview_restart_cache"):
|
||||
return MediaAuthResolution.ADMIN_ONLY, None
|
||||
|
||||
@@ -240,19 +234,15 @@ def _resolve_export(
|
||||
if len(parts) != 2:
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
return _export_camera(Export.video_path, os.path.join(EXPORT_DIR, parts[1]))
|
||||
|
||||
|
||||
def _export_camera(
|
||||
field: Field, full_path: str
|
||||
) -> tuple[MediaAuthResolution, str | None]:
|
||||
filename = parts[1]
|
||||
full_path = os.path.join(EXPORT_DIR, filename)
|
||||
try:
|
||||
export = Export.get(field == full_path)
|
||||
export = Export.get(Export.video_path == full_path)
|
||||
return MediaAuthResolution.CAMERA, export.camera
|
||||
except DoesNotExist:
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
except Exception as e:
|
||||
logger.warning("Export DB lookup failed for %s: %s", full_path, e)
|
||||
logger.warning("Export DB lookup failed for %s: %s", filename, e)
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
|
||||
|
||||
@@ -187,35 +187,16 @@ def build_review_description_response_format(concerns: list[str]) -> dict[str, A
|
||||
|
||||
Strips the `time` field (populated server-side) and drops
|
||||
`other_concerns` when no concerns are configured.
|
||||
|
||||
Every remaining property must be listed in `required` because strict
|
||||
providers (OpenAI) reject a schema with any optional property.
|
||||
"""
|
||||
schema = ReviewMetadata.model_json_schema()
|
||||
properties = schema.setdefault("properties", {})
|
||||
required = schema.setdefault("required", [])
|
||||
properties.pop("time", None)
|
||||
schema.get("properties", {}).pop("time", None)
|
||||
|
||||
if "time" in required:
|
||||
required.remove("time")
|
||||
|
||||
if concerns:
|
||||
# The model field is nullable with a default so stored metadata
|
||||
# without concerns still parses. For generation, require a plain list
|
||||
# instead; the model returns an empty list when no concern applies.
|
||||
properties["other_concerns"] = {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": properties["other_concerns"]["description"],
|
||||
}
|
||||
|
||||
if "other_concerns" not in required:
|
||||
required.append("other_concerns")
|
||||
else:
|
||||
properties.pop("other_concerns", None)
|
||||
|
||||
if "other_concerns" in required:
|
||||
required.remove("other_concerns")
|
||||
if "time" in schema.get("required", []):
|
||||
schema["required"].remove("time")
|
||||
if not concerns:
|
||||
schema.get("properties", {}).pop("other_concerns", None)
|
||||
if "other_concerns" in schema.get("required", []):
|
||||
schema["required"].remove("other_concerns")
|
||||
|
||||
return {
|
||||
"type": "json_schema",
|
||||
|
||||
@@ -7,47 +7,11 @@ from frigate.genai.prompts import (
|
||||
REVIEW_DESCRIPTION_FIELD_GUIDELINES,
|
||||
REVIEW_RESPONSE_STYLES,
|
||||
build_review_description_prompt,
|
||||
build_review_description_response_format,
|
||||
build_review_summary_prompt,
|
||||
get_review_field_guidelines,
|
||||
)
|
||||
|
||||
|
||||
class TestReviewDescriptionResponseFormat(unittest.TestCase):
|
||||
def _schema(self, concerns: list[str]) -> dict:
|
||||
response_format = build_review_description_response_format(concerns)
|
||||
self.assertTrue(response_format["json_schema"]["strict"])
|
||||
return response_format["json_schema"]["schema"]
|
||||
|
||||
def test_every_property_is_required_for_strict_mode(self):
|
||||
for concerns in ([], ["a person loitering near the gate"]):
|
||||
with self.subTest(concerns=concerns):
|
||||
schema = self._schema(concerns)
|
||||
self.assertEqual(set(schema["properties"]), set(schema["required"]))
|
||||
|
||||
def test_time_is_never_requested(self):
|
||||
schema = self._schema(["a person loitering near the gate"])
|
||||
self.assertNotIn("time", schema["properties"])
|
||||
self.assertNotIn("time", schema["required"])
|
||||
|
||||
def test_concerns_omitted_when_not_configured(self):
|
||||
schema = self._schema([])
|
||||
self.assertNotIn("other_concerns", schema["properties"])
|
||||
self.assertNotIn("other_concerns", schema["required"])
|
||||
|
||||
def test_concerns_requested_as_plain_list_when_configured(self):
|
||||
schema = self._schema(["a person loitering near the gate"])
|
||||
concerns = schema["properties"]["other_concerns"]
|
||||
self.assertEqual(concerns["type"], "array")
|
||||
self.assertEqual(concerns["items"], {"type": "string"})
|
||||
self.assertNotIn("anyOf", concerns)
|
||||
self.assertNotIn("default", concerns)
|
||||
|
||||
def test_schema_is_not_shared_between_calls(self):
|
||||
self._schema(["a person loitering near the gate"])
|
||||
self.assertNotIn("other_concerns", self._schema([])["properties"])
|
||||
|
||||
|
||||
class TestReviewResponseStyle(unittest.TestCase):
|
||||
def _build_prompt(self, response_style: str = "default") -> str:
|
||||
review_data = {
|
||||
|
||||
@@ -20,7 +20,7 @@ from frigate.api.media_auth import (
|
||||
resolve_media_uri,
|
||||
)
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import CLIPS_DIR, EXPORT_DIR
|
||||
from frigate.const import EXPORT_DIR
|
||||
from frigate.models import Event, Export, Recordings, ReviewSegment
|
||||
from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS, TEST_DB_PRAGMAS
|
||||
|
||||
@@ -247,7 +247,7 @@ class TestExportResolution(unittest.TestCase):
|
||||
name=f"export-{export_id}",
|
||||
date=int(datetime.datetime.now().timestamp()),
|
||||
video_path=os.path.join(EXPORT_DIR, filename),
|
||||
thumb_path=os.path.join(CLIPS_DIR, "export", f"{export_id}.webp"),
|
||||
thumb_path=os.path.join(EXPORT_DIR, f"{filename}.jpg"),
|
||||
in_progress=False,
|
||||
).execute()
|
||||
|
||||
@@ -280,34 +280,6 @@ class TestExportResolution(unittest.TestCase):
|
||||
resolution, _ = resolve_media_uri("/exports/clip.mp4", self.config)
|
||||
self.assertEqual(resolution, MediaAuthResolution.UNRESOLVED_MEDIA)
|
||||
|
||||
def test_export_thumbnail_resolves_camera(self):
|
||||
self._insert_export("back_door_abc123", "back_door", "back_door_clip.mp4")
|
||||
resolution, camera = resolve_media_uri(
|
||||
"/clips/export/back_door_abc123.webp", self.config
|
||||
)
|
||||
self.assertEqual(resolution, MediaAuthResolution.CAMERA)
|
||||
self.assertEqual(camera, "back_door")
|
||||
|
||||
def test_unknown_export_thumbnail_is_unresolved(self):
|
||||
resolution, _ = resolve_media_uri("/clips/export/missing.webp", self.config)
|
||||
self.assertEqual(resolution, MediaAuthResolution.UNRESOLVED_MEDIA)
|
||||
|
||||
def test_export_thumbnail_gated_by_camera_access(self):
|
||||
self._insert_export("back_door_abc123", "back_door", "back_door_clip.mp4")
|
||||
self._insert_export("front_door_def456", "front_door", "front_door_clip.mp4")
|
||||
url = "/clips/export/{}.webp"
|
||||
self.assertIsNone(
|
||||
deny_response_for_media_uri(
|
||||
url.format("front_door_def456"), "limited_user", self.config
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
deny_response_for_media_uri(
|
||||
url.format("back_door_abc123"), "limited_user", self.config
|
||||
),
|
||||
403,
|
||||
)
|
||||
|
||||
|
||||
class TestDenyResponseForMediaUri(unittest.TestCase):
|
||||
"""End-to-end decision check used by /auth."""
|
||||
|
||||
@@ -511,33 +511,55 @@ class TestHttp(unittest.TestCase):
|
||||
Recordings.get(Recordings.id == rec_d3_id)
|
||||
|
||||
def test_storage_cleanup_keeps_retained(self):
|
||||
"""Ensure cleanup steps over retained segments to reach newer ones."""
|
||||
"""Ensure that all recordings are cleaned up when necessary."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
seg_len = 600
|
||||
base = datetime.datetime.now().timestamp() - 7200
|
||||
_insert_mock_event("123456.keep", base, base + 2.5 * seg_len, True)
|
||||
id = "123456.keep"
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
_insert_mock_event(
|
||||
id,
|
||||
time_keep,
|
||||
time_keep + 30,
|
||||
True,
|
||||
)
|
||||
rec_k_id = "1234567.keep"
|
||||
rec_k2_id = "1234568.keep"
|
||||
rec_k3_id = "1234569.keep"
|
||||
_insert_mock_recording(
|
||||
rec_k_id,
|
||||
os.path.join(self.test_dir, f"{rec_k_id}.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
)
|
||||
_insert_mock_recording(
|
||||
rec_k2_id,
|
||||
os.path.join(self.test_dir, f"{rec_k2_id}.tmp"),
|
||||
time_keep + 10,
|
||||
time_keep + 20,
|
||||
)
|
||||
_insert_mock_recording(
|
||||
rec_k3_id,
|
||||
os.path.join(self.test_dir, f"{rec_k3_id}.tmp"),
|
||||
time_keep + 20,
|
||||
time_keep + 30,
|
||||
)
|
||||
|
||||
paths = {}
|
||||
for i in range(10):
|
||||
rec_id = f"segment-{i}"
|
||||
paths[rec_id] = os.path.join(self.test_dir, f"{rec_id}.tmp")
|
||||
time_delete = datetime.datetime.now().timestamp() - 7200
|
||||
for i in range(0, 59):
|
||||
id = f"{123456 + i}.delete"
|
||||
_insert_mock_recording(
|
||||
rec_id, paths[rec_id], base + i * seg_len, base + (i + 1) * seg_len
|
||||
id,
|
||||
os.path.join(self.test_dir, f"{id}.tmp"),
|
||||
time_delete,
|
||||
time_delete + 600,
|
||||
)
|
||||
|
||||
# Hourly bandwidth is 48 MB, so cleanup needs all 56 MB of unretained
|
||||
# segments and must pass the older retained ones to get there.
|
||||
storage.calculate_camera_bandwidth()
|
||||
storage.reduce_storage_consumption()
|
||||
|
||||
retained = {"segment-0", "segment-1", "segment-2"}
|
||||
remaining = {r.id for r in Recordings.select(Recordings.id)}
|
||||
on_disk = {rec_id for rec_id, path in paths.items() if os.path.exists(path)}
|
||||
self.assertEqual(remaining, retained)
|
||||
self.assertEqual(on_disk, retained)
|
||||
self.assertFalse(storage.retention_unmet)
|
||||
assert Recordings.get(Recordings.id == rec_k_id)
|
||||
assert Recordings.get(Recordings.id == rec_k2_id)
|
||||
assert Recordings.get(Recordings.id == rec_k3_id)
|
||||
|
||||
def test_unmet_retention_sets_the_live_flag(self):
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
|
||||
@@ -28,7 +28,7 @@ export function SummarySegment({
|
||||
<div className="absolute inset-0 flex h-full cursor-pointer justify-end">
|
||||
<div
|
||||
className={cn(
|
||||
"w-full",
|
||||
"w-[10px]",
|
||||
severityColors[severity],
|
||||
height < 0.5 && "min-h-[0.5px]",
|
||||
)}
|
||||
|
||||
@@ -8,26 +8,18 @@ import React, {
|
||||
import { SummarySegment } from "./SummarySegment";
|
||||
import {
|
||||
ConsolidatedSegmentData,
|
||||
MotionData,
|
||||
ReviewSegment,
|
||||
ReviewSeverity,
|
||||
} from "@/types/review";
|
||||
import { useTimelineUtils } from "@/hooks/use-timeline-utils";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { isMobile } from "react-device-detect";
|
||||
|
||||
const MIN_BOX_HEIGHT = isMobile ? 20 : 12;
|
||||
const DRAG_THRESHOLD = 4;
|
||||
|
||||
export type SummaryTimelineProps = {
|
||||
reviewTimelineRef: React.RefObject<HTMLDivElement | null>;
|
||||
timelineStart: number;
|
||||
timelineEnd: number;
|
||||
segmentDuration: number;
|
||||
events?: ReviewSegment[];
|
||||
severityType?: ReviewSeverity;
|
||||
motionData?: MotionData[];
|
||||
motionScale?: number;
|
||||
events: ReviewSegment[];
|
||||
severityType: ReviewSeverity;
|
||||
};
|
||||
|
||||
export function SummaryTimeline({
|
||||
@@ -35,22 +27,16 @@ export function SummaryTimeline({
|
||||
timelineStart,
|
||||
timelineEnd,
|
||||
segmentDuration,
|
||||
events = [],
|
||||
events,
|
||||
severityType,
|
||||
motionData,
|
||||
motionScale,
|
||||
}: SummaryTimelineProps) {
|
||||
const summaryTimelineRef = useRef<HTMLDivElement>(null);
|
||||
const visibleSectionRef = useRef<HTMLDivElement>(null);
|
||||
const motionCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const dragRef = useRef<{
|
||||
startY: number;
|
||||
startScrollTop: number;
|
||||
insideBox: boolean;
|
||||
moved: boolean;
|
||||
} | null>(null);
|
||||
const [scrollStartPosition, setScrollStartPosition] = useState<number>(0);
|
||||
const [initialReviewTimelineScrollTop, setInitialReviewTimelineScrollTop] =
|
||||
useState<number>(0);
|
||||
|
||||
const observer = useRef<ResizeObserver | null>(null);
|
||||
|
||||
@@ -143,79 +129,6 @@ export function SummaryTimeline({
|
||||
segmentDuration,
|
||||
]);
|
||||
|
||||
// Each motion sample covers motionScale seconds with a 0-100 value, and
|
||||
// bins without motion are absent. Opacity is the bucket's mean value.
|
||||
|
||||
const drawMotion = useCallback(() => {
|
||||
const canvas = motionCanvasRef.current;
|
||||
const ctx = canvas?.getContext("2d");
|
||||
|
||||
if (!canvas || !ctx || !motionData || !motionScale) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { clientWidth: width, clientHeight: height } = canvas;
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = width * dpr;
|
||||
canvas.height = height * dpr;
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
const duration = timelineStart - timelineEnd;
|
||||
|
||||
if (duration <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = Math.max(
|
||||
1,
|
||||
Math.min(Math.floor(height), Math.ceil(duration / motionScale)),
|
||||
);
|
||||
const rowHeight = height / rows;
|
||||
const rowSeconds = duration / rows;
|
||||
const sums = new Array<number>(rows).fill(0);
|
||||
|
||||
motionData.forEach((item) => {
|
||||
const row = Math.floor(
|
||||
((timelineStart - item.start_time) / duration) * rows,
|
||||
);
|
||||
|
||||
if (row >= 0 && row < rows) {
|
||||
sums[row] += item.motion ?? 0;
|
||||
}
|
||||
});
|
||||
|
||||
const color = getComputedStyle(document.documentElement)
|
||||
.getPropertyValue("--severity_significant_motion")
|
||||
.trim();
|
||||
|
||||
const samplesPerRow = rowSeconds / motionScale;
|
||||
|
||||
sums.forEach((sum, row) => {
|
||||
if (sum == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const intensity = Math.min(1, sum / (100 * samplesPerRow));
|
||||
ctx.fillStyle = `hsl(${color} / ${intensity})`;
|
||||
ctx.fillRect(0, row * rowHeight, width, Math.ceil(rowHeight));
|
||||
});
|
||||
}, [motionData, motionScale, timelineStart, timelineEnd]);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = motionCanvasRef.current;
|
||||
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawMotion();
|
||||
const resizeObserver = new ResizeObserver(drawMotion);
|
||||
resizeObserver.observe(canvas);
|
||||
|
||||
return () => resizeObserver.disconnect();
|
||||
}, [drawMotion]);
|
||||
|
||||
const setVisibleSectionStyles = useCallback(() => {
|
||||
if (
|
||||
reviewTimelineRef.current &&
|
||||
@@ -231,22 +144,13 @@ export function SummaryTimeline({
|
||||
} = content;
|
||||
const { clientHeight: summaryTimelineVisibleHeight } = summary;
|
||||
|
||||
// The box keeps a minimum height so it stays visible when zoomed in,
|
||||
// centered on the true visible range.
|
||||
|
||||
const trueHeight =
|
||||
summaryTimelineVisibleHeight *
|
||||
(reviewTimelineVisibleHeight / reviewTimelineFullHeight);
|
||||
const trueTop =
|
||||
summaryTimelineVisibleHeight * (scrolled / reviewTimelineFullHeight);
|
||||
const height = Math.max(trueHeight, MIN_BOX_HEIGHT);
|
||||
const top = Math.min(
|
||||
Math.max(trueTop - (height - trueHeight) / 2, 0),
|
||||
summaryTimelineVisibleHeight - height,
|
||||
);
|
||||
|
||||
visibleSectionRef.current.style.top = `${top}px`;
|
||||
visibleSectionRef.current.style.height = `${height}px`;
|
||||
visibleSectionRef.current.style.top = `${
|
||||
summaryTimelineVisibleHeight * (scrolled / reviewTimelineFullHeight)
|
||||
}px`;
|
||||
visibleSectionRef.current.style.height = `${
|
||||
reviewTimelineVisibleHeight *
|
||||
(reviewTimelineVisibleHeight / reviewTimelineFullHeight)
|
||||
}px`;
|
||||
}
|
||||
}, [reviewTimelineRef, summaryTimelineRef, visibleSectionRef]);
|
||||
|
||||
@@ -280,137 +184,178 @@ export function SummaryTimeline({
|
||||
segmentDuration,
|
||||
]);
|
||||
|
||||
const scrollTopForPosition = useCallback(
|
||||
(clientY: number) => {
|
||||
const timeline = reviewTimelineRef.current;
|
||||
const summary = summaryTimelineRef.current;
|
||||
|
||||
if (!timeline || !summary) {
|
||||
return 0;
|
||||
const timelineClick = useCallback(
|
||||
(
|
||||
e: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>,
|
||||
) => {
|
||||
// prevent default only for mouse events
|
||||
// to avoid chrome/android issues
|
||||
if (e.nativeEvent instanceof MouseEvent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
e.stopPropagation();
|
||||
|
||||
const rect = summary.getBoundingClientRect();
|
||||
const ratio = (clientY - rect.top) / rect.height;
|
||||
return ratio * timeline.scrollHeight - timeline.clientHeight / 2;
|
||||
},
|
||||
[reviewTimelineRef],
|
||||
);
|
||||
let clientY;
|
||||
if ("TouchEvent" in window && e.nativeEvent instanceof TouchEvent) {
|
||||
clientY = e.nativeEvent.touches[0].clientY;
|
||||
} else if (e.nativeEvent instanceof MouseEvent) {
|
||||
clientY = e.nativeEvent.clientY;
|
||||
}
|
||||
if (
|
||||
clientY &&
|
||||
reviewTimelineRef.current &&
|
||||
summaryTimelineRef.current &&
|
||||
visibleSectionRef.current
|
||||
) {
|
||||
const { clientHeight: summaryTimelineVisibleHeight } =
|
||||
summaryTimelineRef.current;
|
||||
|
||||
const scrollTimelineTo = useCallback(
|
||||
(top: number, behavior: ScrollBehavior = "auto") => {
|
||||
const timeline = reviewTimelineRef.current;
|
||||
const rect = summaryTimelineRef.current.getBoundingClientRect();
|
||||
const summaryTimelineTop = rect.top;
|
||||
|
||||
if (timeline) {
|
||||
const maxScrollTop = timeline.scrollHeight - timeline.clientHeight;
|
||||
timeline.scrollTo({
|
||||
top: Math.min(Math.max(top, 0), maxScrollTop),
|
||||
behavior,
|
||||
const { scrollHeight: reviewTimelineHeight } =
|
||||
reviewTimelineRef.current;
|
||||
|
||||
const { clientHeight: visibleSectionHeight } =
|
||||
visibleSectionRef.current;
|
||||
|
||||
const visibleSectionOffset = -(visibleSectionHeight / 2);
|
||||
|
||||
const clickPercentage =
|
||||
(clientY - summaryTimelineTop + visibleSectionOffset) /
|
||||
summaryTimelineVisibleHeight;
|
||||
|
||||
reviewTimelineRef.current.scrollTo({
|
||||
top: Math.floor(reviewTimelineHeight * clickPercentage),
|
||||
behavior: "smooth",
|
||||
});
|
||||
}
|
||||
},
|
||||
[reviewTimelineRef],
|
||||
[reviewTimelineRef, summaryTimelineRef, visibleSectionRef],
|
||||
);
|
||||
|
||||
// A press outside the box jumps there on release, or snaps the box under
|
||||
// the pointer once it moves and then drags it.
|
||||
|
||||
const handlePointerDown = useCallback(
|
||||
(e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (
|
||||
e.button != 0 ||
|
||||
!reviewTimelineRef.current ||
|
||||
!visibleSectionRef.current
|
||||
) {
|
||||
return;
|
||||
const handleMouseDown = useCallback(
|
||||
(
|
||||
e: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>,
|
||||
) => {
|
||||
// prevent default only for mouse events
|
||||
// to avoid chrome/android issues
|
||||
if (e.nativeEvent instanceof MouseEvent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
e.stopPropagation();
|
||||
setIsDragging(true);
|
||||
|
||||
let clientY;
|
||||
if ("TouchEvent" in window && e.nativeEvent instanceof TouchEvent) {
|
||||
clientY = e.nativeEvent.touches[0].clientY;
|
||||
} else if (e.nativeEvent instanceof MouseEvent) {
|
||||
clientY = e.nativeEvent.clientY;
|
||||
}
|
||||
if (clientY && summaryTimelineRef.current && reviewTimelineRef.current) {
|
||||
setScrollStartPosition(clientY);
|
||||
setInitialReviewTimelineScrollTop(reviewTimelineRef.current.scrollTop);
|
||||
}
|
||||
},
|
||||
[setIsDragging, summaryTimelineRef, reviewTimelineRef],
|
||||
);
|
||||
|
||||
const handleMouseUp = useCallback(
|
||||
(e: MouseEvent | TouchEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
|
||||
const box = visibleSectionRef.current.getBoundingClientRect();
|
||||
dragRef.current = {
|
||||
startY: e.clientY,
|
||||
startScrollTop: reviewTimelineRef.current.scrollTop,
|
||||
insideBox: e.clientY >= box.top && e.clientY <= box.bottom,
|
||||
moved: false,
|
||||
};
|
||||
if (isDragging) {
|
||||
setIsDragging(false);
|
||||
}
|
||||
},
|
||||
[reviewTimelineRef],
|
||||
[isDragging, setIsDragging],
|
||||
);
|
||||
|
||||
const handlePointerMove = useCallback(
|
||||
(e: React.PointerEvent<HTMLDivElement>) => {
|
||||
const drag = dragRef.current;
|
||||
const timeline = reviewTimelineRef.current;
|
||||
const summary = summaryTimelineRef.current;
|
||||
|
||||
if (!drag || !timeline || !summary) {
|
||||
return;
|
||||
}
|
||||
|
||||
const deltaY = e.clientY - drag.startY;
|
||||
|
||||
if (!drag.moved) {
|
||||
if (Math.abs(deltaY) < DRAG_THRESHOLD) {
|
||||
return;
|
||||
const handleMouseMove = useCallback(
|
||||
(e: MouseEvent | TouchEvent) => {
|
||||
if (
|
||||
summaryTimelineRef.current &&
|
||||
reviewTimelineRef.current &&
|
||||
visibleSectionRef.current
|
||||
) {
|
||||
// prevent default only for mouse events
|
||||
// to avoid chrome/android issues
|
||||
if (e instanceof MouseEvent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
e.stopPropagation();
|
||||
let clientY;
|
||||
if ("TouchEvent" in window && e instanceof TouchEvent) {
|
||||
clientY = e.touches[0].clientY;
|
||||
} else if (e instanceof MouseEvent) {
|
||||
clientY = e.clientY;
|
||||
}
|
||||
if (isDragging && clientY) {
|
||||
const { clientHeight: summaryTimelineVisibleHeight } =
|
||||
summaryTimelineRef.current;
|
||||
|
||||
drag.moved = true;
|
||||
setIsDragging(true);
|
||||
const {
|
||||
scrollHeight: reviewTimelineHeight,
|
||||
clientHeight: reviewTimelineVisibleHeight,
|
||||
} = reviewTimelineRef.current;
|
||||
|
||||
if (!drag.insideBox) {
|
||||
drag.startScrollTop = scrollTopForPosition(drag.startY);
|
||||
const { clientHeight: visibleSectionHeight } =
|
||||
visibleSectionRef.current;
|
||||
|
||||
const deltaY =
|
||||
(clientY - scrollStartPosition) *
|
||||
(summaryTimelineVisibleHeight / visibleSectionHeight);
|
||||
|
||||
const newScrollTop = Math.min(
|
||||
initialReviewTimelineScrollTop + deltaY,
|
||||
reviewTimelineHeight - reviewTimelineVisibleHeight,
|
||||
);
|
||||
|
||||
reviewTimelineRef.current.scrollTop = newScrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
scrollTimelineTo(
|
||||
drag.startScrollTop +
|
||||
deltaY * (timeline.scrollHeight / summary.clientHeight),
|
||||
);
|
||||
},
|
||||
[reviewTimelineRef, scrollTopForPosition, scrollTimelineTo],
|
||||
[
|
||||
initialReviewTimelineScrollTop,
|
||||
isDragging,
|
||||
reviewTimelineRef,
|
||||
scrollStartPosition,
|
||||
],
|
||||
);
|
||||
|
||||
const handlePointerUp = useCallback(
|
||||
(e: React.PointerEvent<HTMLDivElement>) => {
|
||||
const drag = dragRef.current;
|
||||
dragRef.current = null;
|
||||
setIsDragging(false);
|
||||
const documentRef = useRef<Document | null>(document);
|
||||
useEffect(() => {
|
||||
const documentInstance = documentRef.current;
|
||||
|
||||
if (drag && !drag.moved && !drag.insideBox) {
|
||||
scrollTimelineTo(scrollTopForPosition(e.clientY), "smooth");
|
||||
}
|
||||
},
|
||||
[scrollTopForPosition, scrollTimelineTo],
|
||||
);
|
||||
|
||||
const handlePointerCancel = useCallback(() => {
|
||||
dragRef.current = null;
|
||||
setIsDragging(false);
|
||||
}, []);
|
||||
if (isDragging) {
|
||||
documentInstance?.addEventListener("mousemove", handleMouseMove);
|
||||
documentInstance?.addEventListener("touchmove", handleMouseMove);
|
||||
documentInstance?.addEventListener("mouseup", handleMouseUp);
|
||||
documentInstance?.addEventListener("touchend", handleMouseUp);
|
||||
} else {
|
||||
documentInstance?.removeEventListener("mousemove", handleMouseMove);
|
||||
documentInstance?.removeEventListener("touchmove", handleMouseMove);
|
||||
documentInstance?.removeEventListener("mouseup", handleMouseUp);
|
||||
documentInstance?.removeEventListener("touchend", handleMouseUp);
|
||||
}
|
||||
return () => {
|
||||
documentInstance?.removeEventListener("mousemove", handleMouseMove);
|
||||
documentInstance?.removeEventListener("touchmove", handleMouseMove);
|
||||
documentInstance?.removeEventListener("mouseup", handleMouseUp);
|
||||
documentInstance?.removeEventListener("touchend", handleMouseUp);
|
||||
};
|
||||
}, [handleMouseMove, handleMouseUp, isDragging]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"no-scrollbar relative h-full touch-none select-none overflow-hidden border-l-[1px] border-neutral-700 bg-secondary",
|
||||
isDragging ? "cursor-grabbing" : "cursor-pointer",
|
||||
)}
|
||||
className={`no-scrollbar relative h-full select-none overflow-hidden border-l-[1px] border-neutral-700 bg-secondary`}
|
||||
role="scrollbar"
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={handlePointerUp}
|
||||
onPointerCancel={handlePointerCancel}
|
||||
>
|
||||
{motionData && (
|
||||
<canvas
|
||||
ref={motionCanvasRef}
|
||||
className="pointer-events-none absolute inset-0 size-full"
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
ref={summaryTimelineRef}
|
||||
className="relative z-10 flex h-full flex-col-reverse"
|
||||
onClick={timelineClick}
|
||||
onTouchEnd={timelineClick}
|
||||
>
|
||||
{consolidatedSegments.map((segment, index) => (
|
||||
<SummarySegment
|
||||
@@ -422,10 +367,11 @@ export function SummaryTimeline({
|
||||
</div>
|
||||
<div
|
||||
ref={visibleSectionRef}
|
||||
className={cn(
|
||||
"absolute z-20 w-full border-y border-primary/60 bg-primary/30 shadow-[0_0_0_1px_hsl(var(--background))]",
|
||||
!isDragging && "cursor-grab",
|
||||
)}
|
||||
onMouseDown={handleMouseDown}
|
||||
onTouchStart={handleMouseDown}
|
||||
className={`absolute z-20 w-full touch-none bg-primary/30 ${
|
||||
isDragging ? "cursor-grabbing" : "cursor-grab"
|
||||
}`}
|
||||
></div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,6 @@ import i18n, { t } from "i18next";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
import HttpBackend from "i18next-http-backend";
|
||||
import { EventType } from "@/types/search";
|
||||
import { baseUrl } from "@/api/baseUrl";
|
||||
|
||||
export const getTranslatedLabel = (
|
||||
label: string,
|
||||
@@ -34,7 +33,7 @@ i18n
|
||||
fallbackLng: "en", // use en if detected lng is not available
|
||||
|
||||
backend: {
|
||||
loadPath: `${baseUrl}locales/{{lng}}/{{ns}}.json?v=${import.meta.env.VITE_GIT_COMMIT_HASH || "unknown"}`,
|
||||
loadPath: `locales/{{lng}}/{{ns}}.json?v=${import.meta.env.VITE_GIT_COMMIT_HASH || "unknown"}`,
|
||||
},
|
||||
|
||||
ns: [
|
||||
|
||||
@@ -923,7 +923,7 @@ function DetectionReview({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex w-[73px] flex-row md:w-[110px]">
|
||||
<div className="flex w-[65px] flex-row md:w-[110px]">
|
||||
<div className="no-scrollbar relative w-[55px] md:w-[100px]">
|
||||
{loading ? (
|
||||
<Skeleton className="size-full" />
|
||||
@@ -951,7 +951,7 @@ function DetectionReview({
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="w-[18px] md:w-[10px]">
|
||||
<div className="w-[10px]">
|
||||
{loading ? (
|
||||
<Skeleton className="w-full" />
|
||||
) : (
|
||||
@@ -1013,7 +1013,6 @@ function MotionReview({
|
||||
const segmentDuration = 30;
|
||||
const { data: config } = useSWR<FrigateConfig>("config");
|
||||
const allowedCameras = useAllowedCameras();
|
||||
const motionTimelineRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const reviewCameras = useMemo(() => {
|
||||
if (!config) {
|
||||
@@ -1701,58 +1700,34 @@ function MotionReview({
|
||||
</div>
|
||||
</div>
|
||||
{!selectedMotionPreviewCamera && (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-row",
|
||||
motionOnly ? "w-[55px] md:w-[100px]" : "w-[73px] md:w-[110px]",
|
||||
)}
|
||||
>
|
||||
<div className="no-scrollbar w-[55px] overflow-y-auto md:w-[100px]">
|
||||
{motionData ? (
|
||||
<MotionReviewTimeline
|
||||
timelineRef={motionTimelineRef}
|
||||
segmentDuration={segmentDuration}
|
||||
timestampSpread={15}
|
||||
timelineStart={timeRangeSegments.end}
|
||||
timelineEnd={timeRangeSegments.start}
|
||||
motionOnly={motionOnly}
|
||||
showHandlebar
|
||||
handlebarTime={currentTime}
|
||||
setHandlebarTime={setCurrentTime}
|
||||
events={reviewItems?.all ?? []}
|
||||
motion_events={motionData ?? []}
|
||||
contentRef={contentRef}
|
||||
onHandlebarDraggingChange={(scrubbing) => {
|
||||
if (playing && scrubbing) {
|
||||
setPlaying(false);
|
||||
}
|
||||
<div className="no-scrollbar w-[55px] overflow-y-auto md:w-[100px]">
|
||||
{motionData ? (
|
||||
<MotionReviewTimeline
|
||||
segmentDuration={segmentDuration}
|
||||
timestampSpread={15}
|
||||
timelineStart={timeRangeSegments.end}
|
||||
timelineEnd={timeRangeSegments.start}
|
||||
motionOnly={motionOnly}
|
||||
showHandlebar
|
||||
handlebarTime={currentTime}
|
||||
setHandlebarTime={setCurrentTime}
|
||||
events={reviewItems?.all ?? []}
|
||||
motion_events={motionData ?? []}
|
||||
contentRef={contentRef}
|
||||
onHandlebarDraggingChange={(scrubbing) => {
|
||||
if (playing && scrubbing) {
|
||||
setPlaying(false);
|
||||
}
|
||||
|
||||
setScrubbing(scrubbing);
|
||||
}}
|
||||
dense={isMobileOnly}
|
||||
isZooming={false}
|
||||
zoomDirection={null}
|
||||
alwaysShowMotionLine={true}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full" />
|
||||
)}
|
||||
</div>
|
||||
{!motionOnly && (
|
||||
<div className="w-[18px] md:w-[10px]">
|
||||
{motionData ? (
|
||||
<SummaryTimeline
|
||||
reviewTimelineRef={motionTimelineRef}
|
||||
timelineStart={timeRangeSegments.end}
|
||||
timelineEnd={timeRangeSegments.start}
|
||||
segmentDuration={segmentDuration}
|
||||
motionData={motionData}
|
||||
motionScale={segmentDuration / 2}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="w-full" />
|
||||
)}
|
||||
</div>
|
||||
setScrubbing(scrubbing);
|
||||
}}
|
||||
dense={isMobileOnly}
|
||||
isZooming={false}
|
||||
zoomDirection={null}
|
||||
alwaysShowMotionLine={true}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -70,7 +70,6 @@ import { cn } from "@/lib/utils";
|
||||
import { useFullscreen } from "@/hooks/use-fullscreen";
|
||||
import { useTimezone } from "@/hooks/use-date-utils";
|
||||
import { useTimelineZoom } from "@/hooks/use-timeline-zoom";
|
||||
import SummaryTimeline from "@/components/timeline/SummaryTimeline";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTimelineUtils } from "@/hooks/use-timeline-utils";
|
||||
import {
|
||||
@@ -1318,14 +1317,14 @@ function Timeline({
|
||||
isDesktop
|
||||
? cn(
|
||||
timelineType == "timeline"
|
||||
? "w-[110px] flex-shrink-0"
|
||||
? "w-[100px] flex-shrink-0"
|
||||
: timelineType == "detail"
|
||||
? "min-w-[20rem] max-w-[30%] flex-shrink-0 flex-grow-0 basis-[30rem] md:min-w-[20rem] md:max-w-[25%] lg:min-w-[30rem] lg:max-w-[33%]"
|
||||
: "w-80 flex-shrink-0",
|
||||
)
|
||||
: cn(
|
||||
timelineType == "timeline"
|
||||
? "portrait:flex-grow landscape:w-[128px] landscape:flex-shrink-0"
|
||||
? "portrait:flex-grow landscape:w-[100px] landscape:flex-shrink-0"
|
||||
: timelineType == "detail"
|
||||
? "portrait:flex-grow landscape:w-[19rem] landscape:flex-shrink-0"
|
||||
: "portrait:flex-grow landscape:w-[19rem] landscape:flex-shrink-0",
|
||||
@@ -1346,51 +1345,32 @@ function Timeline({
|
||||
)}
|
||||
{timelineType == "timeline" ? (
|
||||
!isLoading ? (
|
||||
<div className="flex size-full flex-row">
|
||||
<div className="relative h-full min-w-0 flex-1">
|
||||
<MotionReviewTimeline
|
||||
timelineRef={selectedTimelineRef}
|
||||
segmentDuration={zoomSettings.segmentDuration}
|
||||
timestampSpread={zoomSettings.timestampSpread}
|
||||
timelineStart={timeRange.before}
|
||||
timelineEnd={timeRange.after}
|
||||
showHandlebar={exportRange == undefined}
|
||||
showExportHandles={exportRange != undefined}
|
||||
exportStartTime={exportRange?.after}
|
||||
exportEndTime={exportRange?.before}
|
||||
setExportStartTime={setExportStartTime}
|
||||
setExportEndTime={setExportEndTime}
|
||||
handlebarTime={currentTime}
|
||||
setHandlebarTime={setCurrentTime}
|
||||
events={mainCameraReviewItems}
|
||||
motion_events={motionData ?? []}
|
||||
noRecordingRanges={noRecordings ?? []}
|
||||
subOnlyRanges={subOnlyRanges}
|
||||
contentRef={contentRef}
|
||||
onHandlebarDraggingChange={setScrubbing}
|
||||
isZooming={isZooming}
|
||||
zoomDirection={zoomDirection}
|
||||
onZoomChange={handleZoomChange}
|
||||
possibleZoomLevels={possibleZoomLevels}
|
||||
currentZoomLevel={currentZoomLevel}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
"flex-shrink-0",
|
||||
isDesktop ? "w-[10px]" : "w-[28px]",
|
||||
)}
|
||||
>
|
||||
<SummaryTimeline
|
||||
reviewTimelineRef={selectedTimelineRef}
|
||||
timelineStart={timeRange.before}
|
||||
timelineEnd={timeRange.after}
|
||||
segmentDuration={zoomSettings.segmentDuration}
|
||||
motionData={motionData}
|
||||
motionScale={Math.round(zoomSettings.segmentDuration / 2)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<MotionReviewTimeline
|
||||
timelineRef={selectedTimelineRef}
|
||||
segmentDuration={zoomSettings.segmentDuration}
|
||||
timestampSpread={zoomSettings.timestampSpread}
|
||||
timelineStart={timeRange.before}
|
||||
timelineEnd={timeRange.after}
|
||||
showHandlebar={exportRange == undefined}
|
||||
showExportHandles={exportRange != undefined}
|
||||
exportStartTime={exportRange?.after}
|
||||
exportEndTime={exportRange?.before}
|
||||
setExportStartTime={setExportStartTime}
|
||||
setExportEndTime={setExportEndTime}
|
||||
handlebarTime={currentTime}
|
||||
setHandlebarTime={setCurrentTime}
|
||||
events={mainCameraReviewItems}
|
||||
motion_events={motionData ?? []}
|
||||
noRecordingRanges={noRecordings ?? []}
|
||||
subOnlyRanges={subOnlyRanges}
|
||||
contentRef={contentRef}
|
||||
onHandlebarDraggingChange={setScrubbing}
|
||||
isZooming={isZooming}
|
||||
zoomDirection={zoomDirection}
|
||||
onZoomChange={handleZoomChange}
|
||||
possibleZoomLevels={possibleZoomLevels}
|
||||
currentZoomLevel={currentZoomLevel}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full" />
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user