mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Handle case where review spans across two hours (#10169)
This commit is contained in:
parent
96bf06a7d8
commit
49530dc2e4
@ -87,16 +87,48 @@ export default function PreviewThumbnailPlayer({
|
||||
|
||||
// playback
|
||||
|
||||
const relevantPreview = useMemo(
|
||||
() =>
|
||||
Object.values(allPreviews || []).find(
|
||||
(preview) =>
|
||||
preview.camera == review.camera &&
|
||||
preview.start < review.start_time &&
|
||||
preview.end > review.end_time,
|
||||
),
|
||||
[allPreviews],
|
||||
);
|
||||
const relevantPreview = useMemo(() => {
|
||||
if (!allPreviews) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let multiHour = false;
|
||||
const firstIndex = Object.values(allPreviews).findIndex((preview) => {
|
||||
if (preview.camera != review.camera || preview.end < review.start_time) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (review.end_time > preview.end) {
|
||||
multiHour = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (firstIndex == -1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!multiHour) {
|
||||
return allPreviews[firstIndex];
|
||||
}
|
||||
|
||||
const firstPrev = allPreviews[firstIndex];
|
||||
const firstDuration = firstPrev.end - review.start_time;
|
||||
const secondDuration = review.end_time - firstPrev.end;
|
||||
|
||||
if (firstDuration > secondDuration) {
|
||||
// the first preview is longer than the second, return the first
|
||||
return firstPrev;
|
||||
} else {
|
||||
// the second preview is longer, return the second if it exists
|
||||
if (firstIndex < allPreviews.length - 1) {
|
||||
return allPreviews[firstIndex + 1];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}, [allPreviews]);
|
||||
|
||||
const playingBack = useMemo(() => playback, [playback]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user