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 type RecordingReviewLinkState = {
|
||||
@ -7,22 +5,6 @@ export type RecordingReviewLinkState = {
|
||||
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(
|
||||
value: string | null,
|
||||
): RecordingReviewLinkState | undefined {
|
||||
@ -30,16 +12,13 @@ export function parseRecordingReviewLink(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const [camera, start, timezone] = value.split("|");
|
||||
const [camera, timestamp] = value.split("|");
|
||||
|
||||
if (!camera || !start) {
|
||||
if (!camera || !timestamp) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const parsedDate = timezone
|
||||
? fromZonedTime(start, timezone)
|
||||
: new Date(start);
|
||||
const parsedTimestamp = parsedDate.getTime() / 1000;
|
||||
const parsedTimestamp = Number(timestamp);
|
||||
|
||||
if (!Number.isFinite(parsedTimestamp)) {
|
||||
return undefined;
|
||||
@ -54,19 +33,12 @@ export function parseRecordingReviewLink(
|
||||
export function createRecordingReviewUrl(
|
||||
pathname: string,
|
||||
state: RecordingReviewLinkState,
|
||||
timezone?: string,
|
||||
): string {
|
||||
const url = new URL(globalThis.location.href);
|
||||
const formattedTimestamp = formatRecordingReviewTimestamp(
|
||||
state.timestamp,
|
||||
timezone,
|
||||
);
|
||||
const normalizedPathname = pathname.startsWith("/")
|
||||
? pathname
|
||||
: `/${pathname}`;
|
||||
const reviewLink = timezone
|
||||
? `${state.camera}|${formattedTimestamp}|${timezone}`
|
||||
: `${state.camera}|${formattedTimestamp}`;
|
||||
const reviewLink = `${state.camera}|${Math.floor(state.timestamp)}`;
|
||||
|
||||
return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
|
||||
}
|
||||
|
||||
@ -335,14 +335,10 @@ export function RecordingView({
|
||||
|
||||
const onShareReviewLink = useCallback(
|
||||
(timestamp: number) => {
|
||||
const reviewUrl = createRecordingReviewUrl(
|
||||
location.pathname,
|
||||
{
|
||||
camera: mainCamera,
|
||||
timestamp: Math.floor(timestamp),
|
||||
},
|
||||
config?.ui.timezone,
|
||||
);
|
||||
const reviewUrl = createRecordingReviewUrl(location.pathname, {
|
||||
camera: mainCamera,
|
||||
timestamp: Math.floor(timestamp),
|
||||
});
|
||||
|
||||
shareOrCopy(
|
||||
reviewUrl,
|
||||
@ -352,7 +348,7 @@ export function RecordingView({
|
||||
}),
|
||||
);
|
||||
},
|
||||
[location.pathname, mainCamera, config?.ui.timezone, t],
|
||||
[location.pathname, mainCamera, t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user