Add limit support for recordings.
This commit is contained in:
@@ -5,10 +5,10 @@ import getUnixTime from 'date-fns/getUnixTime';
|
|||||||
import startOfHour from 'date-fns/startOfHour';
|
import startOfHour from 'date-fns/startOfHour';
|
||||||
import { CAMERA_BIRDSEYE } from '../../const';
|
import { CAMERA_BIRDSEYE } from '../../const';
|
||||||
import { CameraConfig, RecordingSegment } from '../../types';
|
import { CameraConfig, RecordingSegment } from '../../types';
|
||||||
import { MediaQueriesResults } from "../../view/media-queries-results";
|
import { MediaQueriesResults } from '../../view/media-queries-results';
|
||||||
import { MediaQueriesClassifier } from "../../view/media-queries-classifier";
|
import { MediaQueriesClassifier } from '../../view/media-queries-classifier';
|
||||||
import { ViewMedia, ViewMediaFactory } from '../../view/media';
|
import { ViewMedia, ViewMediaFactory } from '../../view/media';
|
||||||
import { ViewMediaClassifier } from "../../view/media-classifier";
|
import { ViewMediaClassifier } from '../../view/media-classifier';
|
||||||
import { errorToConsole } from '../../utils/basic';
|
import { errorToConsole } from '../../utils/basic';
|
||||||
import { RecordingSegmentsCache } from '../cache';
|
import { RecordingSegmentsCache } from '../cache';
|
||||||
import {
|
import {
|
||||||
@@ -34,8 +34,16 @@ import {
|
|||||||
RecordingSegmentsQuery,
|
RecordingSegmentsQuery,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { FrigateRecording, RecordingSummary } from './types';
|
import { FrigateRecording, RecordingSummary } from './types';
|
||||||
import { getEvents, getRecordingSegments, getRecordingsSummary, NativeFrigateEventQuery, NativeFrigateRecordingSegmentsQuery, retainEvent } from './requests';
|
import {
|
||||||
|
getEvents,
|
||||||
|
getRecordingSegments,
|
||||||
|
getRecordingsSummary,
|
||||||
|
NativeFrigateEventQuery,
|
||||||
|
NativeFrigateRecordingSegmentsQuery,
|
||||||
|
retainEvent,
|
||||||
|
} from './requests';
|
||||||
import { MediaQueries } from '../../view/media-queries';
|
import { MediaQueries } from '../../view/media-queries';
|
||||||
|
import orderBy from 'lodash-es/orderBy';
|
||||||
|
|
||||||
const EVENT_REQUEST_CACHE_MAX_AGE_SECONDS = 60;
|
const EVENT_REQUEST_CACHE_MAX_AGE_SECONDS = 60;
|
||||||
const RECORDING_SUMMARY_REQUEST_CACHE_MAX_AGE_SECONDS = 60;
|
const RECORDING_SUMMARY_REQUEST_CACHE_MAX_AGE_SECONDS = 60;
|
||||||
@@ -182,13 +190,12 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: FrigateEventQueryResults = {
|
return <FrigateEventQueryResults>{
|
||||||
type: QueryResultsType.Event,
|
type: QueryResultsType.Event,
|
||||||
engine: Engine.Frigate,
|
engine: Engine.Frigate,
|
||||||
events: await getEvents(hass, nativeQuery),
|
events: await getEvents(hass, nativeQuery),
|
||||||
expiry: add(new Date(), { seconds: EVENT_REQUEST_CACHE_MAX_AGE_SECONDS }),
|
expiry: add(new Date(), { seconds: EVENT_REQUEST_CACHE_MAX_AGE_SECONDS }),
|
||||||
};
|
};
|
||||||
return result;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e as Error);
|
||||||
throw new CameraManagerError((e as Error).message, query);
|
throw new CameraManagerError((e as Error).message, query);
|
||||||
@@ -220,7 +227,8 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
|
|||||||
throw new CameraManagerError((e as Error).message, query);
|
throw new CameraManagerError((e as Error).message, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordings: FrigateRecording[] = [];
|
let recordings: FrigateRecording[] = [];
|
||||||
|
|
||||||
for (const dayData of recordingSummary ?? []) {
|
for (const dayData of recordingSummary ?? []) {
|
||||||
for (const hourData of dayData.hours) {
|
for (const hourData of dayData.hours) {
|
||||||
const hour = add(dayData.day, { hours: hourData.hour });
|
const hour = add(dayData.day, { hours: hourData.hour });
|
||||||
@@ -240,6 +248,16 @@ export class FrigateCameraManagerEngine implements CameraManagerEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query.limit !== undefined) {
|
||||||
|
// Frigate does not natively support a way to limit recording searches so
|
||||||
|
// this simulates it.
|
||||||
|
recordings = orderBy(
|
||||||
|
recordings,
|
||||||
|
(recording: FrigateRecording) => recording.start_time,
|
||||||
|
'desc',
|
||||||
|
).slice(0, query.limit);
|
||||||
|
}
|
||||||
|
|
||||||
return <FrigateRecordingQueryResults>{
|
return <FrigateRecordingQueryResults>{
|
||||||
type: QueryResultsType.Recording,
|
type: QueryResultsType.Recording,
|
||||||
engine: Engine.Frigate,
|
engine: Engine.Frigate,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Easy:
|
// Easy:
|
||||||
// - TODO: Refactor thumbnailsControlSchema to all use the shortform for other thumbnail users beyond live.
|
// - TODO: Refactor thumbnailsControlSchema to all use the shortform for other thumbnail users beyond live.
|
||||||
// - TODO: limit param in recordings should do something
|
|
||||||
// - TODO: Should be able to set live media to 'all' and have it work.
|
// - TODO: Should be able to set live media to 'all' and have it work.
|
||||||
// - TODO: Are there elements of ViewMedia (e.g. getEventCount) that should be moved into subclasses (e.g. a recording subclass).
|
// - TODO: Are there elements of ViewMedia (e.g. getEventCount) that should be moved into subclasses (e.g. a recording subclass).
|
||||||
// - TODO: In MediaQueriesBase, do we need to generic? Just have T be a MediaQuery?
|
// - TODO: In MediaQueriesBase, do we need to generic? Just have T be a MediaQuery?
|
||||||
@@ -11,7 +10,6 @@
|
|||||||
// - TODO: Add garbage collecting of segments not present in the recording summaries anymore.
|
// - TODO: Add garbage collecting of segments not present in the recording summaries anymore.
|
||||||
// - TODO: Do I need to dedup recordings? (i.e. multiple zones on same camera may need to be dedup'd somewhere before returning the view). The media getID() call may be useful for this.
|
// - TODO: Do I need to dedup recordings? (i.e. multiple zones on same camera may need to be dedup'd somewhere before returning the view). The media getID() call may be useful for this.
|
||||||
// - TODO: Do a fresh media query in the viewer on snapshot click, since the first query may (e.g.) only have requested events with snapshots (which would miss an event with just a clip).
|
// - TODO: Do a fresh media query in the viewer on snapshot click, since the first query may (e.g.) only have requested events with snapshots (which would miss an event with just a clip).
|
||||||
// - TODO: Move view/ stuff into a view directory.
|
|
||||||
// - TODO: Move frigate specific view-media under the camera manager.
|
// - TODO: Move frigate specific view-media under the camera manager.
|
||||||
// - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript
|
// - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user