2026-03-19 23:54:54 +03:00
|
|
|
export const RECORDING_REVIEW_LINK_PARAM = "timestamp";
|
2026-03-19 01:02:48 +03:00
|
|
|
|
|
|
|
|
export type RecordingReviewLinkState = {
|
|
|
|
|
camera: string;
|
|
|
|
|
timestamp: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function parseRecordingReviewLink(
|
2026-03-19 23:54:54 +03:00
|
|
|
value: string | null,
|
2026-03-19 01:02:48 +03:00
|
|
|
): 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) {
|
2026-03-19 01:02:48 +03:00
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 00:19:33 +03:00
|
|
|
const parsedTimestamp = Number(timestamp);
|
2026-03-19 01:02:48 +03:00
|
|
|
|
|
|
|
|
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 01:02:48 +03:00
|
|
|
|
2026-03-19 23:54:54 +03:00
|
|
|
return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
|
2026-03-19 01:02:48 +03:00
|
|
|
}
|