Change URL format to unix timestamps

This commit is contained in:
0x464e 2026-03-19 23:19:33 +02:00
parent d8f7ca27ed
commit 64dcf77361
No known key found for this signature in database
GPG Key ID: E6D221DF6CBFBFFA
2 changed files with 9 additions and 41 deletions

View File

@ -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}`;
}

View File

@ -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(() => {