frigate/web/src/utils/recordingReviewUrl.ts

45 lines
1005 B
TypeScript
Raw Normal View History

2026-03-19 23:54:54 +03:00
export const RECORDING_REVIEW_LINK_PARAM = "timestamp";
export type RecordingReviewLinkState = {
camera: string;
timestamp: number;
};
export function parseRecordingReviewLink(
2026-03-19 23:54:54 +03:00
value: string | null,
): RecordingReviewLinkState | undefined {
2026-03-19 23:54:54 +03:00
if (!value) {
return undefined;
}
2026-03-20 00:19:33 +03:00
const [camera, timestamp] = value.split("|");
2026-03-19 23:54:54 +03:00
2026-03-20 00:19:33 +03:00
if (!camera || !timestamp) {
return undefined;
}
2026-03-20 00:19:33 +03:00
const parsedTimestamp = Number(timestamp);
if (!Number.isFinite(parsedTimestamp)) {
return undefined;
}
return {
camera,
timestamp: Math.floor(parsedTimestamp),
};
}
export function createRecordingReviewUrl(
pathname: string,
state: RecordingReviewLinkState,
): string {
2026-03-19 17:33:30 +03:00
const url = new URL(globalThis.location.href);
const normalizedPathname = pathname.startsWith("/")
? pathname
: `/${pathname}`;
2026-03-20 00:19:33 +03:00
const reviewLink = `${state.camera}|${Math.floor(state.timestamp)}`;
2026-03-19 23:54:54 +03:00
return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
}