mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-03 22:04:53 +03:00
Change URL format to unix timestamps
This commit is contained in:
parent
d8f7ca27ed
commit
64dcf77361
@ -1,5 +1,3 @@
|
|||||||
import { formatInTimeZone, fromZonedTime } from "date-fns-tz";
|
|
||||||
|
|
||||||
export const RECORDING_REVIEW_LINK_PARAM = "timestamp";
|
export const RECORDING_REVIEW_LINK_PARAM = "timestamp";
|
||||||
|
|
||||||
export type RecordingReviewLinkState = {
|
export type RecordingReviewLinkState = {
|
||||||
@ -7,22 +5,6 @@ export type RecordingReviewLinkState = {
|
|||||||
timestamp: number;
|
timestamp: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatRecordingReviewTimestamp(
|
|
||||||
timestamp: number,
|
|
||||||
timezone: string | undefined,
|
|
||||||
): string {
|
|
||||||
const date = new Date(Math.floor(timestamp) * 1000);
|
|
||||||
|
|
||||||
if (timezone) {
|
|
||||||
// when the UI timezone is configured, keep the URL readable by storing
|
|
||||||
// local time plus a separate timezone query param
|
|
||||||
return formatInTimeZone(date, timezone, "yyyy-MM-dd'T'HH:mm:ss");
|
|
||||||
}
|
|
||||||
|
|
||||||
// without a configured UI timezone, fall back to UTC timestamp
|
|
||||||
return formatInTimeZone(date, "UTC", "yyyy-MM-dd'T'HH:mm:ss'Z'");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseRecordingReviewLink(
|
export function parseRecordingReviewLink(
|
||||||
value: string | null,
|
value: string | null,
|
||||||
): RecordingReviewLinkState | undefined {
|
): RecordingReviewLinkState | undefined {
|
||||||
@ -30,16 +12,13 @@ export function parseRecordingReviewLink(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [camera, start, timezone] = value.split("|");
|
const [camera, timestamp] = value.split("|");
|
||||||
|
|
||||||
if (!camera || !start) {
|
if (!camera || !timestamp) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedDate = timezone
|
const parsedTimestamp = Number(timestamp);
|
||||||
? fromZonedTime(start, timezone)
|
|
||||||
: new Date(start);
|
|
||||||
const parsedTimestamp = parsedDate.getTime() / 1000;
|
|
||||||
|
|
||||||
if (!Number.isFinite(parsedTimestamp)) {
|
if (!Number.isFinite(parsedTimestamp)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -54,19 +33,12 @@ export function parseRecordingReviewLink(
|
|||||||
export function createRecordingReviewUrl(
|
export function createRecordingReviewUrl(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
state: RecordingReviewLinkState,
|
state: RecordingReviewLinkState,
|
||||||
timezone?: string,
|
|
||||||
): string {
|
): string {
|
||||||
const url = new URL(globalThis.location.href);
|
const url = new URL(globalThis.location.href);
|
||||||
const formattedTimestamp = formatRecordingReviewTimestamp(
|
|
||||||
state.timestamp,
|
|
||||||
timezone,
|
|
||||||
);
|
|
||||||
const normalizedPathname = pathname.startsWith("/")
|
const normalizedPathname = pathname.startsWith("/")
|
||||||
? pathname
|
? pathname
|
||||||
: `/${pathname}`;
|
: `/${pathname}`;
|
||||||
const reviewLink = timezone
|
const reviewLink = `${state.camera}|${Math.floor(state.timestamp)}`;
|
||||||
? `${state.camera}|${formattedTimestamp}|${timezone}`
|
|
||||||
: `${state.camera}|${formattedTimestamp}`;
|
|
||||||
|
|
||||||
return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
|
return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -335,14 +335,10 @@ export function RecordingView({
|
|||||||
|
|
||||||
const onShareReviewLink = useCallback(
|
const onShareReviewLink = useCallback(
|
||||||
(timestamp: number) => {
|
(timestamp: number) => {
|
||||||
const reviewUrl = createRecordingReviewUrl(
|
const reviewUrl = createRecordingReviewUrl(location.pathname, {
|
||||||
location.pathname,
|
camera: mainCamera,
|
||||||
{
|
timestamp: Math.floor(timestamp),
|
||||||
camera: mainCamera,
|
});
|
||||||
timestamp: Math.floor(timestamp),
|
|
||||||
},
|
|
||||||
config?.ui.timezone,
|
|
||||||
);
|
|
||||||
|
|
||||||
shareOrCopy(
|
shareOrCopy(
|
||||||
reviewUrl,
|
reviewUrl,
|
||||||
@ -352,7 +348,7 @@ export function RecordingView({
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[location.pathname, mainCamera, config?.ui.timezone, t],
|
[location.pathname, mainCamera, t],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user