Skip to content

NVR with realtime local object detection for IP cameras

Clone camera settings (#23339)

Josh Hawkinsbc65713ae4df
diff --git a/web/e2e/specs/clone-camera.spec.ts b/web/e2e/specs/clone-camera.spec.ts
new file mode 100644
index 0000000000..1c75e71a3d
--- /dev/null
+++ b/web/e2e/specs/clone-camera.spec.ts
@@ -0,0 +1,181 @@
+/**
+ * Camera clone dialog E2E tests.
+ *
+ * Covers the design invariants that don't depend on per-camera resolution
+ * differences in the mock fixture:
+ * 1. Dialog opens from the "Clone settings" button below Add/Delete.
+ * 2. A source camera must be chosen inside the dialog before cloning.
+ * 3. "Stream URLs and roles" is forced on and disabled for new-camera target.
+ * 4. Cloning to a new camera issues a single add PUT and shows a restart prompt.
+ * 5. The existing-camera target selects multiple destinations via a switch
+ * popover (with an "All cameras" toggle and source exclusion); the closed
+ * trigger summarizes the selection by name or as "All cameras".
+ *
+ * The spatial-mismatch warning path is exercised in unit-level review and via
+ * manual QA — the shared mock fixture ships every camera at 1280×720. The
+ * existing-camera PUT fan-out is likewise not asserted here: the mock cameras
+ * are identical apart from stream URLs (which existing-camera clones never
+ * copy) and the schema mock is empty, so a clone onto them produces no diff
+ * and no PUT. That path is covered by unit-level review and manual QA.
+ */
+
+import { test, expect } from "../fixtures/frigate-test";
+
+async function openCloneDialog(frigateApp: {
+ page: import("@playwright/test").Page;
+}) {
+ await frigateApp.page
+ .getByRole("button", { name: /^Clone settings$/i })
+ .click();
+ await expect(frigateApp.page.getByRole("dialog")).toBeVisible();
+}
+
+async function selectSource(
+ frigateApp: { page: import("@playwright/test").Page },
+ source: string,
+) {
+ await frigateApp.page.getByRole("dialog").getByRole("combobox").click();
+ await frigateApp.page
+ .getByRole("option", { name: source, exact: true })
+ .click();
+}
+
+test.describe("Camera clone dialog @medium @mobile", () => {
+ test.beforeEach(async ({ frigateApp }) => {
+ await frigateApp.goto("/settings?page=cameraManagement");
+ await expect(
+ frigateApp.page.getByRole("heading", { name: /Manage Cameras/i }),
+ ).toBeVisible();
+ });
+
+ test("opens the dialog from the Clone settings button", async ({
+ frigateApp,
+ }) => {
+ await openCloneDialog(frigateApp);
+
+ await expect(
+ frigateApp.page.getByRole("dialog").getByText(/Clone camera settings/i),
+ ).toBeVisible();
+
+ // The Clone button is disabled until a source (and target) is chosen.
+ await expect(
+ frigateApp.page.getByRole("button", { name: /^Clone$/i }),
+ ).toBeDisabled();
+ });
+
+ test("forces Stream URLs and roles on for new-camera target", async ({
+ frigateApp,
+ }) => {
+ await openCloneDialog(frigateApp);
+ await selectSource(frigateApp, "Front Door");
+
+ // The "New camera" radio is selected by default; the Streams group renders
+ // the ffmpeg_live checkbox as forced-checked and disabled.
+ const streamsLabel = frigateApp.page
+ .locator("label")
+ .filter({ hasText: /Stream URLs and roles/i });
+ await expect(streamsLabel).toBeVisible();
+
+ const streamsCheckbox = streamsLabel.getByRole("checkbox");
+ await expect(streamsCheckbox).toBeChecked();
+ await expect(streamsCheckbox).toBeDisabled();
+ });
+
+ test("issues a single add PUT and shows restart toast for new-camera target", async ({
+ frigateApp,
+ }) => {
+ const requests: { body: unknown }[] = [];
+
+ await frigateApp.page.route("**/api/config/set", async (route) => {
+ const body = route.request().postDataJSON();
+ requests.push({ body });
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({ success: true, require_restart: false }),
+ });
+ });
+
+ await frigateApp.goto("/settings?page=cameraManagement");
+ await expect(
+ frigateApp.page.getByRole("heading", { name: /Manage Cameras/i }),
+ ).toBeVisible();
+
+ await openCloneDialog(frigateApp);
+ await selectSource(frigateApp, "Front Door");
+
+ const nameInput = frigateApp.page.getByPlaceholder(
+ /e\.g\., back_door or Back Door/i,
+ );
+ await nameInput.fill("clone_target_one");
+
+ // With a source picked and a valid name, changeCount > 0 enables Clone.
+ await expect(
+ frigateApp.page.getByRole("button", { name: /^Clone$/i }),
+ ).toBeEnabled({ timeout: 5_000 });
+
+ await frigateApp.page.getByRole("button", { name: /^Clone$/i }).click();
+
+ // New-camera clones bundle into a single atomic add PUT (avoids
+ // per-section validation ordering issues).
+ await expect.poll(() => requests.length, { timeout: 10_000 }).toBe(1);
+
+ const firstBody = requests[0].body as {
+ requires_restart?: number;
+ update_topic?: string;
+ };
+ expect(firstBody.update_topic).toMatch(
+ /config\/cameras\/clone_target_one\/add/,
+ );
+ expect(firstBody.requires_restart).toBe(1);
+
+ // The toast offers a Restart action because new-camera always needs restart.
+ // .first() avoids strict-mode rejection when both the toast action and the
+ // RestartDialog trigger render concurrently.
+ await expect(
+ frigateApp.page.getByRole("button", { name: /Restart/i }).first(),
+ ).toBeVisible({ timeout: 8_000 });
+ });
+
+ test("selects multiple existing destination cameras via a switch popover", async ({
+ frigateApp,
+ }) => {
+ await openCloneDialog(frigateApp);
+ await selectSource(frigateApp, "Front Door");
+
+ await frigateApp.page
+ .getByRole("radio", { name: /Existing cameras/i })
+ .click();
+
+ const dialog = frigateApp.page.getByRole("dialog");
+
+ // The destination trigger starts with the empty-selection placeholder.
+ await dialog
+ .getByRole("button", { name: /Select at least one camera/i })
+ .click();
+
+ // The chosen source is excluded from the destination switch list.
+ await expect(
+ dialog.getByRole("switch", { name: /Backyard/i }),
+ ).toBeVisible();
+ await expect(dialog.getByRole("switch", { name: /Garage/i })).toBeVisible();
+ await expect(
+ dialog.getByRole("switch", { name: /^Front Door$/i }),
+ ).toHaveCount(0);
+
+ // Selecting a single camera summarizes by name once the popover closes.
+ await dialog.getByRole("switch", { name: /Backyard/i }).click();
+ await frigateApp.page.keyboard.press("Escape");
+ await expect(
+ dialog.getByRole("button", { name: /^Backyard$/i }),
+ ).toBeVisible();
+
+ // Reopen and select everything; the trigger collapses to "All cameras".
+ await dialog.getByRole("button", { name: /^Backyard$/i }).click();
+ await dialog.getByRole("switch", { name: /^All cameras$/i }).click();
+ await frigateApp.page.keyboard.press("Escape");
+ await expect(
+ dialog.getByRole("button", { name: /^All cameras$/i }),
+ ).toBeVisible();
+ });
+});
diff --git a/web/public/locales/en/views/settings.json b/web/public/locales/en/views/settings.json
index 966f83d725..2374c506e7 100644
--- a/web/public/locales/en/views/settings.json
+++ b/web/public/locales/en/views/settings.json
@@ -544,6 +544,92 @@
"normal": "Normal",
"dedicatedLpr": "Dedicated LPR",
"saveSuccess": "Updated camera type for {{cameraName}}. Restart Frigate to apply the changes."
+ },
+ "clone": {
+ "sectionTitle": "Clone settings",
+ "sectionDescription": "Copy configuration from one camera to another camera or a new one.",
+ "button": "Clone settings",
+ "title": "Clone camera settings",
+ "description": "Copy a camera's configuration to one or more other cameras or a new camera. Identity (name, friendly name, web UI URL, display order) is never copied.",
+ "source": {
+ "label": "Source camera",
+ "placeholder": "Select a source camera",
+ "required": "Select a source camera"
+ },
+ "target": {
+ "legend": "Target",
+ "newRadio": "New camera",
+ "newNameLabel": "Camera name",
+ "newNamePlaceholder": "e.g., back_door or Back Door",
+ "newNameRequired": "Camera name is required",
+ "newNameInvalid": "Invalid camera name",
+ "newNameCollision": "A camera with this name already exists",
+ "newStreamsForced": "Streams are always copied for a new camera.",
+ "existingCamerasRadio": "Existing cameras",
+ "allCameras": "All cameras",
+ "existingPlaceholder": "Select at least one camera",
+ "existingDisabled": "No other cameras to copy to"
+ },
+ "categories": {
+ "legend": "Settings to clone",
+ "description": "Choose which settings to copy from the source camera.",
+ "selectAll": "Select all",
+ "selectNone": "Select none",
+ "resetDefaults": "Reset to defaults",
+ "general": "General",
+ "spatial": "Spatial settings",
+ "streams": "Streams",
+ "spatialWarningTitle": "Resolution mismatch",
+ "spatialWarning": "Source camera {{srcCamera}} detect resolution ({{srcWidth}}×{{srcHeight}}) differs from: {{cameras}}. Polygons may not align on those cameras. These defaults are off; enable to copy as-is.",
+ "restartHint": "Restart required",
+ "items": {
+ "record": "Recording",
+ "snapshots": "Snapshots",
+ "review": "Review",
+ "motion": "Motion detection",
+ "objects": "Objects",
+ "audio": "Audio detection",
+ "audio_transcription": "Audio transcription",
+ "notifications": "Notifications",
+ "birdseye": "Birdseye",
+ "mqtt": "MQTT",
+ "timestamp_style": "Timestamp style",
+ "onvif": "ONVIF",
+ "lpr": "License plate recognition",
+ "face_recognition": "Face recognition",
+ "semantic_search": "Semantic search",
+ "genai": "Generative AI",
+ "type": "Camera type (normal / dedicated LPR)",
+ "profiles": "Profiles",
+ "detect": "Detect dimensions",
+ "zones": "Zones",
+ "motion_mask": "Motion masks",
+ "object_masks": "Object masks",
+ "ffmpeg_live": "Stream URLs and roles"
+ }
+ },
+ "footer": {
+ "changeCount_zero": "No changes selected",
+ "changeCount_one": "{{count}} change will be applied",
+ "changeCount_other": "{{count}} changes will be applied",
+ "restartNeeded": "Restart will be required for some changes.",
+ "liveOnly": "All changes will apply live without a restart.",
+ "submit": "Clone",
+ "submitting": "Cloning…"
+ },
+ "toast": {
+ "success": "Settings copied to {{cameraName}}",
+ "successWithRestart": "Settings copied to {{cameraName}}. Restart Frigate to apply all changes.",
+ "successMulti_one": "Settings copied to {{count}} camera",
+ "successMulti_other": "Settings copied to {{count}} cameras",
+ "successMultiWithRestart_one": "Settings copied to {{count}} camera. Restart Frigate to apply all changes.",
+ "successMultiWithRestart_other": "Settings copied to {{count}} cameras. Restart Frigate to apply all changes.",
+ "partialFailure": "{{successCount}} sections applied; '{{failedSection}}' failed: {{errorMessage}}",
+ "partialFailureMulti": "Copied to {{successCount}} camera(s); failed for {{failed}}: {{errorMessage}}",
+ "newCameraPartialFailure": "Camera {{cameraName}} was created but some settings failed to copy: {{errorMessage}}",
+ "sourceMissing": "Source camera no longer exists",
+ "submitError": "Failed to clone camera: {{errorMessage}}"
+ }
}
},
"cameraReview": {
diff --git a/web/src/components/overlay/detail/SaveAllPreviewPopover.tsx b/web/src/components/overlay/detail/SaveAllPreviewPopover.tsx
index a775935315..e65b347de8 100644
--- a/web/src/components/overlay/detail/SaveAllPreviewPopover.tsx
+++ b/web/src/components/overlay/detail/SaveAllPreviewPopover.tsx
@@ -22,6 +22,7 @@ type SaveAllPreviewPopoverProps = {
className?: string;
align?: "start" | "center" | "end";
side?: "top" | "bottom" | "left" | "right";
+ disablePortal?: boolean;
};
export default function SaveAllPreviewPopover({
@@ -29,6 +30,7 @@ export default function SaveAllPreviewPopover({
className,
align = "end",
side = "bottom",
+ disablePortal = false,
}: SaveAllPreviewPopoverProps) {
const { t } = useTranslation(["views/settings", "common"]);
const [open, setOpen] = useState(false);
@@ -67,6 +69,7 @@ export default function SaveAllPreviewPopover({
<PopoverContent
align={align}
side={side}
+ disablePortal={disablePortal}
className="w-[90vw] max-w-sm border bg-background p-4 shadow-lg"
onOpenAutoFocus={(event) => event.preventDefault()}
>
@@ -108,13 +111,13 @@ export default function SaveAllPreviewPopover({
}`}
className="rounded-md border border-secondary bg-background_alt p-2"
>
- <div className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs">
+ <div className="grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs">
<span className="text-muted-foreground">
{t("saveAllPreview.scope.label", {
ns: "views/settings",
})}
</span>
- <span className="truncate">{scopeLabel}</span>
+ <span className="min-w-0 truncate">{scopeLabel}</span>
{item.profileName && (
<>
<span className="text-muted-foreground">
@@ -122,7 +125,7 @@ export default function SaveAllPreviewPopover({
ns: "views/settings",
})}
</span>
- <span className="truncate font-medium">
+ <span className="min-w-0 truncate font-medium">
{item.profileName}
</span>
</>
@@ -132,7 +135,7 @@ export default function SaveAllPreviewPopover({
ns: "views/settings",
})}
</span>
- <span className="break-all font-mono">
+ <span className="min-w-0 break-all font-mono">
{item.fieldPath}
</span>
<span className="text-muted-foreground">
@@ -140,7 +143,7 @@ export default function SaveAllPreviewPopover({
ns: "views/settings",
})}
</span>
- <span className="whitespace-pre-wrap break-words font-mono">
+ <span className="min-w-0 whitespace-pre-wrap break-all font-mono">
{formatValue(item.value)}
</span>
</div>
diff --git a/web/src/components/settings/CloneCameraDialog.tsx b/web/src/components/settings/CloneCameraDialog.tsx
new file mode 100644
index 0000000000..61458211b8
--- /dev/null
+++ b/web/src/components/settings/CloneCameraDialog.tsx
@@ -0,0 +1,1046 @@
+import {
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+import { useForm, useWatch } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+import { useTranslation } from "react-i18next";
+import useSWR, { mutate as swrMutate } from "swr";
+import axios from "axios";
+import { toast } from "sonner";
+
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form";
+import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { cn } from "@/lib/utils";
+import { isReplayCamera, processCameraName } from "@/utils/cameraUtil";
+import type { FrigateConfig } from "@/types/frigateConfig";
+import { Checkbox } from "@/components/ui/checkbox";
+import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
+import { Label } from "@/components/ui/label";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { LuArrowRight, LuChevronDown, LuTriangleAlert } from "react-icons/lu";
+import {
+ CLONE_CATEGORIES,
+ type CloneCategoryKey,
+ type CloneCategoryGroup,
+ type RawCameraPaths,
+ getCategoryDefaults,
+ resolutionsMatch,
+ buildClonedCameraPayloads,
+ buildClonePreviewItems,
+} from "@/utils/cameraClone";
+import { buildConfigDataForPath } from "@/utils/configUtil";
+import { useConfigSchema } from "@/hooks/use-config-schema";
+import { useRestart } from "@/api/ws";
+import { StatusBarMessagesContext } from "@/context/statusbar-provider";
+import RestartDialog from "@/components/overlay/dialog/RestartDialog";
+import ActivityIndicator from "@/components/indicators/activity-indicator";
+import SaveAllPreviewPopover from "@/components/overlay/detail/SaveAllPreviewPopover";
+import FilterSwitch from "@/components/filter/FilterSwitch";
+
+type CloneCameraDialogProps = {
+ open: boolean;
+ onClose: () => void;
+};
+
+type CloneFormValues = {
+ sourceCamera: string;
+ targetMode: "new" | "existing";
+ newName: string;
+ existingTargets: string[];
+};
+
+export default function CloneCameraDialog({
+ open,
+ onClose,
+}: CloneCameraDialogProps) {
+ const { t } = useTranslation(["views/settings", "common"]);
+ const { data: config } = useSWR<FrigateConfig>("config");
+ const { data: rawPaths } = useSWR<RawCameraPaths>("config/raw_paths");
+ const [isSubmitting, setIsSubmitting] = useState(false);
+
+ const sourceCameras = useMemo(() => {
+ if (!config) return [];
+ return Object.keys(config.cameras)
+ .filter((c) => !isReplayCamera(c))
+ .sort();
+ }, [config]);
+
+ const formSchema = useMemo(() => {
+ const reservedNames = new Set<string>([
+ ...(config ? Object.keys(config.cameras) : []),
+ ...(config?.go2rtc?.streams ? Object.keys(config.go2rtc.streams) : []),
+ ]);
+ return z
+ .object({
+ sourceCamera: z.string(),
+ targetMode: z.enum(["new", "existing"]),
+ newName: z.string(),
+ existingTargets: z.array(z.string()),
+ })
+ .superRefine((data, ctx) => {
+ if (!data.sourceCamera) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["sourceCamera"],
+ message: t("cameraManagement.clone.source.required"),
+ });
+ }
+ if (data.targetMode === "new") {
+ const trimmed = data.newName.trim();
+ if (!trimmed) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["newName"],
+ message: t("cameraManagement.clone.target.newNameRequired"),
+ });
+ return;
+ }
+ const { finalCameraName } = processCameraName(trimmed);
+ if (!finalCameraName) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["newName"],
+ message: t("cameraManagement.clone.target.newNameInvalid"),
+ });
+ return;
+ }
+ if (reservedNames.has(finalCameraName)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["newName"],
+ message: t("cameraManagement.clone.target.newNameCollision"),
+ });
+ }
+ } else if (data.existingTargets.length === 0) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["existingTargets"],
+ message: t("cameraManagement.clone.target.existingPlaceholder"),
+ });
+ }
+ });
+ }, [config, t]);
+
+ const form = useForm<CloneFormValues>({
+ resolver: zodResolver(formSchema),
+ mode: "onChange",
+ defaultValues: {
+ sourceCamera: "",
+ targetMode: "new",
+ newName: "",
+ existingTargets: [],
+ },
+ });
+
+ const sourceCamera = form.watch("sourceCamera");
+ const targetMode = form.watch("targetMode");
+ const existingTargets = form.watch("existingTargets");
+
+ const targetIsNew = targetMode === "new";
+
+ const otherCameras = useMemo(() => {
+ if (!config) return [];
+ return Object.keys(config.cameras)
+ .filter((c) => c !== sourceCamera && !isReplayCamera(c))
+ .sort();
+ }, [config, sourceCamera]);
+
+ const srcCfg = config?.cameras?.[sourceCamera];
+
+ // Existing targets whose detect resolution differs from the source. Spatial
+ // settings use detect-resolution coordinates, so cloning them to a camera
+ // with a different resolution is flagged (but still allowed).
+ const mismatchedTargets = useMemo(() => {
+ if (targetIsNew || !srcCfg?.detect) return [];
+ return existingTargets.filter((cam) => {
+ const dst = config?.cameras?.[cam];
+ return dst?.detect && !resolutionsMatch(srcCfg.detect, dst.detect);
+ });
+ }, [targetIsNew, srcCfg, existingTargets, config]);
+
+ const allResMatch = mismatchedTargets.length === 0;
+
+ const [selectedCategories, setSelectedCategories] = useState<
+ Set<CloneCategoryKey>
+ >(() => getCategoryDefaults(true));
+
+ // Reset form + selection only on the open transition
+ const wasOpenRef = useRef(false);
+ useEffect(() => {
+ if (open && !wasOpenRef.current) {
+ wasOpenRef.current = true;
+ form.reset({
+ sourceCamera: "",
+ targetMode: "new",
+ newName: "",
+ existingTargets: [],
+ });
+ setSelectedCategories(getCategoryDefaults(true));
+ } else if (!open) {
+ wasOpenRef.current = false;
+ }
+ }, [open, form]);
+
+ // Drop the source camera from the target selection if it gets picked.
+ useEffect(() => {
+ if (!sourceCamera) return;
+ const current = form.getValues("existingTargets");
+ if (current.includes(sourceCamera)) {
+ form.setValue(
+ "existingTargets",
+ current.filter((c) => c !== sourceCamera),
+ );
+ }
+ }, [sourceCamera, form]);
+
+ // Reset selection to per-mode defaults when the user switches target mode.
+ useEffect(() => {
+ setSelectedCategories(getCategoryDefaults(targetIsNew));
+ }, [targetIsNew]);
+
+ const toggleCategory = useCallback((key: CloneCategoryKey) => {
+ setSelectedCategories((prev) => {
+ const next = new Set(prev);
+ if (next.has(key)) next.delete(key);
+ else next.add(key);
+ return next;
+ });
+ }, []);
+
+ const selectAllCategories = useCallback(() => {
+ setSelectedCategories((prev) => {
+ const next = new Set(prev);
+ const includeSpatial = targetIsNew || allResMatch;
+ for (const cat of CLONE_CATEGORIES) {
+ if (cat.newCameraOnly && !targetIsNew) continue;
+ if (cat.group === "spatial" && !includeSpatial) continue;
+ if (cat.group === "streams") continue;
+ next.add(cat.key);
+ }
+ return next;
+ });
+ }, [targetIsNew, allResMatch]);
+
+ const selectNoneCategories = useCallback(() => {
+ setSelectedCategories((prev) => {
+ const next = new Set<CloneCategoryKey>();
+ for (const cat of CLONE_CATEGORIES) {
+ if (cat.group === "streams" && prev.has(cat.key)) {
+ next.add(cat.key);
+ }
+ }
+ return next;
+ });
+ }, []);
+
+ const visibleCategories = useMemo(
+ () => CLONE_CATEGORIES.filter((c) => targetIsNew || !c.newCameraOnly),
+ [targetIsNew],
+ );
+
+ const groupedCategories = useMemo(() => {
+ const groups: Record<CloneCategoryGroup, typeof visibleCategories> = {
+ general: [],
+ spatial: [],
+ streams: [],
+ };
+ for (const c of visibleCategories) {
+ groups[c.group].push(c);
+ }
+ return groups;
+ }, [visibleCategories]);
+
+ const sourceFriendlyName =
+ config?.cameras?.[sourceCamera]?.friendly_name ?? sourceCamera;
+
+ const fullSchema = useConfigSchema();
+ const { send: sendRestart } = useRestart();
+ const statusBar = useContext(StatusBarMessagesContext);
+ const [restartDialogOpen, setRestartDialogOpen] = useState(false);
+
+ const watchedNewName =
+ useWatch({ control: form.control, name: "newName" }) ?? "";
+
+ // Payloads grouped per destination camera. New mode has a single target;
+ // existing mode fans out across every selected camera.
+ const targetPayloads = useMemo<
+ { target: string; payloads: ReturnType<typeof buildClonedCameraPayloads> }[]
+ >(() => {
+ if (!config || !fullSchema || !srcCfg) {
+ return [];
+ }
+ if (targetIsNew) {
+ const finalName = processCameraName(watchedNewName || "").finalCameraName;
+ if (!watchedNewName || !finalName) return [];
+ return [
+ {
+ target: finalName,
+ payloads: buildClonedCameraPayloads({
+ sourceCfg: srcCfg,
+ sourceName: sourceCamera,
+ targetInput: watchedNewName,
+ targetIsNew: true,
+ selectedKeys: selectedCategories,
+ fullConfig: config,
+ fullSchema,
+ rawPaths,
+ }),
+ },
+ ];
+ }
+ return existingTargets
+ .filter((cam) => config.cameras?.[cam])
+ .map((cam) => ({
+ target: cam,
+ payloads: buildClonedCameraPayloads({
+ sourceCfg: srcCfg,
+ sourceName: sourceCamera,
+ targetInput: cam,
+ targetIsNew: false,
+ selectedKeys: selectedCategories,
+ fullConfig: config,
+ fullSchema,
+ rawPaths,
+ }),
+ }));
+ }, [
+ config,
+ fullSchema,
+ srcCfg,
+ sourceCamera,
+ targetIsNew,
+ existingTargets,
+ watchedNewName,
+ selectedCategories,
+ rawPaths,
+ ]);
+
+ const previewPayloads = useMemo(
+ () => targetPayloads.flatMap((tp) => tp.payloads),
+ [targetPayloads],
+ );
+
+ const previewItems = useMemo(
+ () =>
+ targetPayloads.flatMap((tp) =>
+ buildClonePreviewItems(tp.payloads, tp.target),
+ ),
+ [targetPayloads],
+ );
+
+ const anyNeedsRestart = previewPayloads.some((p) => p.needsRestart);
+ const changeCount = previewItems.length;
+
+ const onSubmit = useCallback(
+ async (values: CloneFormValues) => {
+ if (!config || !srcCfg || !fullSchema) return;
+ if (previewPayloads.length === 0) {
+ toast.error(
+ t("cameraManagement.clone.toast.submitError", {
+ errorMessage: t("cameraManagement.clone.footer.changeCount", {
+ count: 0,
+ }),
+ }),
+ );
+ return;
+ }
+
+ const friendlyName = (cam: string) =>
+ config.cameras?.[cam]?.friendly_name ?? cam;
+
+ const extractError = (error: unknown) =>
+ (axios.isAxiosError(error) &&
+ (error.response?.data?.message || error.response?.data?.detail)) ||
+ (error instanceof Error ? error.message : "Unknown error");
+
+ const restartAction = (
+ <a onClick={() => setRestartDialogOpen(true)}>
+ <Button>{t("restart.button", { ns: "components/dialog" })}</Button>
+ </a>
+ );
+
+ const markRestartRequired = () =>
+ statusBar?.addMessage(
+ "config_restart_required",
+ t("configForm.restartRequiredFooter"),
+ undefined,
+ "config_restart_required",
+ );
+
+ setIsSubmitting(true);
+
+ if (targetIsNew) {
+ const targetLabel = values.newName.trim();
+ const payloads = targetPayloads[0]?.payloads ?? [];
+ let appliedCount = 0;
+ let failedSection: string | undefined;
+ let failureMessage: string | undefined;
+
+ try {
+ for (const payload of payloads) {
+ try {
+ await axios.put("config/set", {
+ requires_restart: payload.needsRestart ? 1 : 0,
+ update_topic: payload.updateTopic,
+ config_data: buildConfigDataForPath(
+ payload.basePath,
+ payload.sanitizedOverrides,
+ ),
+ });
+ appliedCount += 1;
+ } catch (error) {
+ failedSection = payload.basePath;
+ failureMessage = extractError(error);
+ break;
+ }
+ }
+ } finally {
+ await swrMutate("config");
+ setIsSubmitting(false);
+ }
+
+ if (failedSection) {
+ toast.error(
+ appliedCount > 0
+ ? t("cameraManagement.clone.toast.newCameraPartialFailure", {
+ cameraName: targetLabel,
+ errorMessage: failureMessage,
+ })
+ : t("cameraManagement.clone.toast.partialFailure", {
+ successCount: appliedCount,
+ failedSection,
+ errorMessage: failureMessage,
+ }),
+ { position: "top-center" },
+ );
+ return;
+ }
+
+ if (anyNeedsRestart) {
+ markRestartRequired();
+ toast.success(
+ t("cameraManagement.clone.toast.successWithRestart", {
+ cameraName: targetLabel,
+ }),
+ { position: "top-center", duration: 10000, action: restartAction },
+ );
+ } else {
+ toast.success(
+ t("cameraManagement.clone.toast.success", {
+ cameraName: targetLabel,
+ }),
+ { position: "top-center" },
+ );
+ }
+
+ onClose();
+ return;
+ }
+
+ // One or more existing cameras: keep going if a camera fails, summarize.
+ const succeeded: string[] = [];
+ const failed: string[] = [];
+ let lastError: string | undefined;
+
+ try {
+ for (const { target, payloads } of targetPayloads) {
+ let cameraError: string | undefined;
+ for (const payload of payloads) {
+ try {
+ await axios.put("config/set", {
+ requires_restart: payload.needsRestart ? 1 : 0,
+ update_topic: payload.updateTopic,
+ config_data: buildConfigDataForPath(
+ payload.basePath,
+ payload.sanitizedOverrides,
+ ),
+ });
+ } catch (error) {
+ cameraError = extractError(error);
+ break;
+ }
+ }
+ if (cameraError) {
+ failed.push(friendlyName(target));
+ lastError = cameraError;
+ } else {
+ succeeded.push(friendlyName(target));
+ }
+ }
+ } finally {
+ await swrMutate("config");
+ setIsSubmitting(false);
+ }
+
+ if (failed.length > 0) {
+ toast.error(
+ t("cameraManagement.clone.toast.partialFailureMulti", {
+ successCount: succeeded.length,
+ failed: failed.join(", "),
+ errorMessage: lastError,
+ }),
+ { position: "top-center", duration: 10000 },
+ );
+ return;
+ }
+
+ const singleLabel = succeeded.length === 1 ? succeeded[0] : undefined;
+
+ if (anyNeedsRestart) {
+ markRestartRequired();
+ toast.success(
+ singleLabel
+ ? t("cameraManagement.clone.toast.successWithRestart", {
+ cameraName: singleLabel,
+ })
+ : t("cameraManagement.clone.toast.successMultiWithRestart", {
+ count: succeeded.length,
+ }),
+ { position: "top-center", duration: 10000, action: restartAction },
+ );
+ } else {
+ toast.success(
+ singleLabel
+ ? t("cameraManagement.clone.toast.success", {
+ cameraName: singleLabel,
+ })
+ : t("cameraManagement.clone.toast.successMulti", {
+ count: succeeded.length,
+ }),
+ { position: "top-center" },
+ );
+ }
+
+ onClose();
+ },
+ [
+ config,
+ srcCfg,
+ fullSchema,
+ previewPayloads,
+ targetPayloads,
+ targetIsNew,
+ anyNeedsRestart,
+ onClose,
+ statusBar,
+ t,
+ ],
+ );
+
+ return (
+ <Dialog open={open} onOpenChange={(o) => !o && onClose()}>
+ <DialogContent
+ className={cn(
+ "scrollbar-container max-h-[90dvh] max-w-4xl overflow-y-auto",
+ )}
+ onInteractOutside={(e) => e.preventDefault()}
+ >
+ <DialogHeader>
+ <DialogTitle>{t("cameraManagement.clone.title")}</DialogTitle>
+ <DialogDescription>
+ {t("cameraManagement.clone.description")}
+ </DialogDescription>
+ </DialogHeader>
+
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
+ <div className="relative flex flex-col gap-6 md:grid md:grid-cols-2 md:items-start md:gap-12">
+ <div className="space-y-3">
+ <Label className="text-base">
+ {t("cameraManagement.clone.source.label")}
+ </Label>
+ <FormField
+ control={form.control}
+ name="sourceCamera"
+ render={({ field }) => (
+ <FormItem>
+ <FormControl>
+ <Select
+ value={field.value}
+ onValueChange={field.onChange}
+ disabled={isSubmitting}
+ >
+ <SelectTrigger className="w-full max-w-xs md:max-w-none">
+ <SelectValue
+ placeholder={t(
+ "cameraManagement.clone.source.placeholder",
+ )}
+ />
+ </SelectTrigger>
+ <SelectContent>
+ {sourceCameras.map((cam) => (
+ <SelectItem key={cam} value={cam}>
+ {config?.cameras?.[cam]?.friendly_name ?? cam}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ <div className="space-y-3">
+ <Label className="text-base">
+ {t("cameraManagement.clone.target.legend")}
+ </Label>
+ <FormField
+ control={form.control}
+ name="targetMode"
+ render={({ field }) => (
+ <FormItem>
+ <FormControl>
+ <RadioGroup
+ value={field.value}
+ onValueChange={field.onChange}
+ className="space-y-3"
+ >
+ <div className="space-y-2">
+ <div className="flex items-center space-x-3 space-y-0">
+ <RadioGroupItem
+ value="new"
+ id="clone-target-new"
+ className={
+ targetMode === "new"
+ ? "bg-selected from-selected/50 to-selected/90 text-selected"
+ : "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
+ }
+ />
+ <Label
+ htmlFor="clone-target-new"
+ className="font-normal"
+ >
+ {t("cameraManagement.clone.target.newRadio")}
+ </Label>
+ </div>
+ {targetMode === "new" && (
+ <FormItem>
+ <FormLabel className="sr-only">
+ {t(
+ "cameraManagement.clone.target.newNameLabel",
+ )}
+ </FormLabel>
+ <FormControl>
+ <Input
+ {...form.register("newName")}
+ className="max-w-xs md:max-w-none"
+ placeholder={t(
+ "cameraManagement.clone.target.newNamePlaceholder",
+ )}
+ disabled={isSubmitting}
+ autoFocus
+ />
+ </FormControl>
+ {form.formState.errors.newName?.message && (
+ <p className="text-sm font-medium text-destructive">
+ {String(
+ form.formState.errors.newName.message,
+ )}
+ </p>
+ )}
+ <p className="text-xs text-muted-foreground">
+ {t(
+ "cameraManagement.clone.target.newStreamsForced",
+ )}
+ </p>
+ </FormItem>
+ )}
+ </div>
+ <div className="space-y-2">
+ <div className="flex items-center space-x-3 space-y-0">
+ <RadioGroupItem
+ value="existing"
+ id="clone-target-existing"
+ disabled={otherCameras.length === 0}
+ className={
+ targetMode === "existing"
+ ? "bg-selected from-selected/50 to-selected/90 text-selected"
+ : "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
+ }
+ />
+ <Label
+ htmlFor="clone-target-existing"
+ className={cn(
+ "font-normal",
+ otherCameras.length === 0 &&
+ "text-muted-foreground",
+ )}
+ >
+ {t(
+ "cameraManagement.clone.target.existingCamerasRadio",
+ )}
+ {otherCameras.length === 0 && (
+ <span className="ml-2 text-xs">
+ (
+ {t(
+ "cameraManagement.clone.target.existingDisabled",
+ )}
+ )
+ </span>
+ )}
+ </Label>
+ </div>
+ {targetMode === "existing" &&
+ otherCameras.length > 0 && (
+ <FormField
+ control={form.control}
+ name="existingTargets"
+ render={({ field: tgtField }) => {
+ const selected = tgtField.value ?? [];
+ const allSelected =
+ otherCameras.length > 0 &&
+ otherCameras.every((c) =>
+ selected.includes(c),
+ );
+ const selectedNames = otherCameras
+ .filter((c) => selected.includes(c))
+ .map(
+ (c) =>
+ config?.cameras?.[c]?.friendly_name ??
+ c,
+ );
+ const summary = allSelected
+ ? t(
+ "cameraManagement.clone.target.allCameras",
+ )
+ : selectedNames.length > 0
+ ? selectedNames.join(", ")
+ : t(
+ "cameraManagement.clone.target.existingPlaceholder",
+ );
+ return (
+ <FormItem>
+ <Popover>
+ <FormControl>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="outline"
+ disabled={isSubmitting}
+ className="w-full max-w-xs justify-between font-normal md:max-w-none"
+ >
+ <span
+ className={cn(
+ "truncate",
+ selectedNames.length ===
+ 0 &&
+ "text-muted-foreground",
+ )}
+ >
+ {summary}
+ </span>
+ <LuChevronDown className="ml-2 size-4 shrink-0 opacity-50" />
+ </Button>
+ </PopoverTrigger>
+ </FormControl>
+ <PopoverContent
+ align="start"
+ disablePortal
+ className="w-[--radix-popover-trigger-width] p-0"
+ >
+ <div className="scrollbar-container max-h-60 space-y-4 overflow-y-auto p-4">
+ <FilterSwitch
+ label={t(
+ "cameraManagement.clone.target.allCameras",
+ )}
+ isChecked={allSelected}
+ disabled={isSubmitting}
+ onCheckedChange={(checked) =>
+ tgtField.onChange(
+ checked
+ ? [...otherCameras]
+ : [],
+ )
+ }
+ />
+ <div className="space-y-2.5">
+ {otherCameras.map((cam) => (
+ <FilterSwitch
+ key={cam}
+ label={cam}
+ type="camera"
+ isChecked={selected.includes(
+ cam,
+ )}
+ disabled={isSubmitting}
+ onCheckedChange={(
+ checked,
+ ) =>
+ tgtField.onChange(
+ checked
+ ? [...selected, cam]
+ : selected.filter(
+ (c) => c !== cam,
+ ),
+ )
+ }
+ />
+ ))}
+ </div>
+ </div>
+ </PopoverContent>
+ </Popover>
+ <FormMessage />
+ </FormItem>
+ );
+ }}
+ />
+ )}
+ </div>
+ </RadioGroup>
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ </div>
+
+ <div className="pointer-events-none absolute left-1/2 top-0 hidden -translate-x-1/2 flex-col space-y-3 md:flex">
+ <Label className="invisible text-base" aria-hidden="true">
+ {" "}
+ </Label>
+ <div className="flex h-10 items-center justify-center">
+ <LuArrowRight className="size-6 text-muted-foreground" />
+ </div>
+ </div>
+ </div>
+
+ <div className="space-y-4">
+ <div className="flex flex-col gap-2 md:flex-row md:items-end md:justify-between">
+ <div className="space-y-1">
+ <Label className="text-base">
+ {t("cameraManagement.clone.categories.legend")}
+ </Label>
+ <p className="text-xs text-muted-foreground">
+ {t("cameraManagement.clone.categories.description")}
+ </p>
+ </div>
+ <div className="flex flex-row items-center gap-2 text-xs text-muted-foreground">
+ <span
+ className="cursor-pointer whitespace-nowrap"
+ onClick={isSubmitting ? undefined : selectAllCategories}
+ >
+ {t("cameraManagement.clone.categories.selectAll")}
+ </span>
+ <span aria-hidden="true">|</span>
+ <span
+ className="cursor-pointer whitespace-nowrap"
+ onClick={isSubmitting ? undefined : selectNoneCategories}
+ >
+ {t("cameraManagement.clone.categories.selectNone")}
+ </span>
+ </div>
+ </div>
+
+ <div className="space-y-2">
+ <Label className="font-medium">
+ {t("cameraManagement.clone.categories.general")}
+ </Label>
+ <div className="grid grid-cols-1 gap-x-12 gap-y-3 rounded-lg bg-secondary p-4 sm:grid-cols-2">
+ {groupedCategories.general.map((cat) => (
+ <label
+ key={cat.key}
+ className="flex flex-row items-center space-x-3 space-y-0 text-sm font-normal"
+ >
+ <Checkbox
+ className="size-5 text-white accent-white data-[state=checked]:bg-selected data-[state=checked]:text-white"
+ checked={selectedCategories.has(cat.key)}
+ onCheckedChange={() => toggleCategory(cat.key)}
+ disabled={isSubmitting}
+ />
+ <span>
+ {t(
+ `cameraManagement.clone.categories.items.${cat.key}`,
+ )}
+ </span>
+ </label>
+ ))}
+ </div>
+ </div>
+
+ {groupedCategories.spatial.length > 0 && (
+ <div className="space-y-2">
+ <Label className="font-medium">
+ {t("cameraManagement.clone.categories.spatial")}
+ </Label>
+ {!targetIsNew &&
+ srcCfg?.detect &&
+ mismatchedTargets.length > 0 && (
+ <Alert variant="warning">
+ <LuTriangleAlert className="size-5" />
+ <AlertTitle>
+ {t(
+ "cameraManagement.clone.categories.spatialWarningTitle",
+ )}
+ </AlertTitle>
+ <AlertDescription>
+ {t(
+ "cameraManagement.clone.categories.spatialWarning",
+ {
+ srcCamera: sourceFriendlyName,
+ srcWidth: srcCfg.detect.width,
+ srcHeight: srcCfg.detect.height,
+ cameras: mismatchedTargets
+ .map(
+ (c) =>
+ config?.cameras?.[c]?.friendly_name ?? c,
+ )
+ .join(", "),
+ },
+ )}
+ </AlertDescription>
+ </Alert>
+ )}
+ <div className="grid grid-cols-1 gap-x-12 gap-y-3 rounded-lg bg-secondary p-4 sm:grid-cols-2">
+ {groupedCategories.spatial.map((cat) => (
+ <label
+ key={cat.key}
+ className="flex flex-row items-center space-x-3 space-y-0 text-sm font-normal"
+ >
+ <Checkbox
+ className="size-5 text-white accent-white data-[state=checked]:bg-selected data-[state=checked]:text-white"
+ checked={selectedCategories.has(cat.key)}
+ onCheckedChange={() => toggleCategory(cat.key)}
+ disabled={isSubmitting}
+ />
+ <span>
+ {t(
+ `cameraManagement.clone.categories.items.${cat.key}`,
+ )}
+ </span>
+ </label>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {targetIsNew && groupedCategories.streams.length > 0 && (
+ <div className="space-y-2">
+ <Label className="font-medium">
+ {t("cameraManagement.clone.categories.streams")}
+ </Label>
+ <div className="grid grid-cols-1 gap-3 rounded-lg bg-secondary p-4">
+ {groupedCategories.streams.map((cat) => (
+ <label
+ key={cat.key}
+ className="flex flex-row items-center space-x-3 space-y-0 text-sm font-normal text-muted-foreground"
+ >
+ <Checkbox
+ className="size-5 text-white accent-white data-[state=checked]:bg-selected data-[state=checked]:text-white"
+ checked
+ disabled
+ />
+ <span>
+ {t(
+ `cameraManagement.clone.categories.items.${cat.key}`,
+ )}
+ </span>
+ </label>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+
+ <DialogFooter className="flex flex-col items-stretch gap-3 sm:flex-row sm:items-center sm:justify-between sm:space-x-0">
+ <div className="flex flex-col gap-1 text-sm text-muted-foreground">
+ {changeCount > 0 && (
+ <>
+ <div className="flex items-center gap-1">
+ <span>
+ {t("cameraManagement.clone.footer.changeCount", {
+ count: changeCount,
+ })}
+ </span>
+ {changeCount > 0 && (
+ <SaveAllPreviewPopover
+ items={previewItems}
+ className="h-7 w-7"
+ align="start"
+ side="top"
+ disablePortal
+ />
+ )}
+ </div>
+ <span className="text-xs">
+ {anyNeedsRestart
+ ? t("cameraManagement.clone.footer.restartNeeded")
+ : t("cameraManagement.clone.footer.liveOnly")}
+ </span>
+ </>
+ )}
+ </div>
+ <div className="flex w-full flex-col gap-2 sm:w-auto sm:flex-row">
+ <Button
+ type="button"
+ disabled={isSubmitting}
+ onClick={onClose}
+ className="w-full sm:w-auto"
+ >
+ {t("button.cancel", { ns: "common" })}
+ </Button>
+ <Button
+ variant="select"
+ type="submit"
+ disabled={isSubmitting || changeCount === 0}
+ className="w-full sm:w-auto"
+ >
+ {isSubmitting ? (
+ <div className="flex items-center gap-2">
+ <ActivityIndicator className="size-4" />
+ <span>
+ {t("cameraManagement.clone.footer.submitting")}
+ </span>
+ </div>
+ ) : (
+ t("cameraManagement.clone.footer.submit")
+ )}
+ </Button>
+ </div>
+ </DialogFooter>
+ </form>
+ </Form>
+ <RestartDialog
+ isOpen={restartDialogOpen}
+ onClose={() => setRestartDialogOpen(false)}
+ onRestart={() => sendRestart("restart")}
+ />
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/web/src/utils/cameraClone.ts b/web/src/utils/cameraClone.ts
new file mode 100644
index 0000000000..c985c917f0
--- /dev/null
+++ b/web/src/utils/cameraClone.ts
@@ -0,0 +1,856 @@
+import cloneDeep from "lodash/cloneDeep";
+import isEqual from "lodash/isEqual";
+import merge from "lodash/merge";
+import type { RJSFSchema } from "@rjsf/utils";
+
+import {
+ buildOverrides,
+ cameraUpdateTopicMap,
+ flattenOverrides,
+ getEffectiveAttributeLabels,
+ getSectionConfig,
+ prepareSectionSavePayload,
+ resolveHiddenFieldEntries,
+ sanitizeSectionData,
+ type SectionSavePayload,
+} from "@/utils/configUtil";
+import { applySchemaDefaults } from "@/lib/config-schema";
+import type { SaveAllPreviewItem } from "@/components/overlay/detail/SaveAllPreviewPopover";
+import type { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
+import type {
+ ConfigSectionData,
+ JsonObject,
+ JsonValue,
+} from "@/types/configForm";
+import { processCameraName } from "@/utils/cameraUtil";
+
+/**
+ * Sections whose `filters` dict is auto-populated by the backend at parse
+ * time. `attributeBump` reflects the global-level `min_score=0.7` override
+ * the backend applies to attribute labels (face, license_plate, Frigate+
+ * couriers) — see `frigate/config/config.py`.
+ */
+const FILTER_SECTION_DEFS: Record<
+ string,
+ {
+ listField: string;
+ filterDef: string;
+ attributeBump?: { min_score: number };
+ }
+> = {
+ objects: {
+ listField: "track",
+ filterDef: "FilterConfig",
+ attributeBump: { min_score: 0.7 },
+ },
+ audio: { listField: "listen", filterDef: "AudioFilterConfig" },
+};
+
+function resolveDef(schema: RJSFSchema, name: string): RJSFSchema | undefined {
+ const defs =
+ (schema as { $defs?: Record<string, RJSFSchema> }).$defs ??
+ (schema as { definitions?: Record<string, RJSFSchema> }).definitions;
+ return defs ? defs[name] : undefined;
+}
+
+/**
+ * Reduce each filter entry to the fields that differ from the backend's
+ * auto-default. An entry that is entirely auto-populated drops out; a
+ * partially-customized entry keeps only its customized fields, so cloning
+ * doesn't copy the auto-populated default for every other field.
+ */
+function stripAutoDefaultFilters(
+ section: string,
+ sourceSection: JsonObject,
+ fullSchema: RJSFSchema,
+ fullConfig: FrigateConfig,
+ fullCameraConfig: CameraConfig,
+): JsonObject {
+ const def = FILTER_SECTION_DEFS[section];
+ if (!def) return sourceSection;
+ const filters = sourceSection.filters;
+ if (!filters || typeof filters !== "object" || Array.isArray(filters)) {
+ return sourceSection;
+ }
+ const filterDef = resolveDef(fullSchema, def.filterDef);
+ if (!filterDef) return sourceSection;
+ const baseDefaults = applySchemaDefaults(filterDef, {}) as JsonObject;
+ const attributeDefaults = def.attributeBump
+ ? ({ ...baseDefaults, ...def.attributeBump } as JsonObject)
+ : baseDefaults;
+ const attributeSet =
+ section === "objects"
+ ? new Set(
+ getEffectiveAttributeLabels(fullConfig, fullCameraConfig, "camera"),
+ )
+ : new Set<string>();
+
+ // Ignore runtime-only `mask`/`raw_mask`: the API ships them as `{}` while the
+ // schema default omits them, which would otherwise break the equality check.
+ const withoutRuntimeFields = (entry: JsonValue): JsonValue => {
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
+ return entry;
+ }
+ const copy = { ...(entry as JsonObject) };
+ delete copy.mask;
+ delete copy.raw_mask;
+ return copy;
+ };
+
+ const cleaned: JsonObject = {};
+ for (const [label, value] of Object.entries(filters as JsonObject)) {
+ const expected = attributeSet.has(label) ? attributeDefaults : baseDefaults;
+ const valNorm = withoutRuntimeFields(value as JsonValue);
+ const expNorm = withoutRuntimeFields(expected as JsonValue);
+
+ // Non-object filter value: keep only if it differs from the default.
+ if (
+ !valNorm ||
+ typeof valNorm !== "object" ||
+ Array.isArray(valNorm) ||
+ !expNorm ||
+ typeof expNorm !== "object" ||
+ Array.isArray(expNorm)
+ ) {
+ if (!isEqual(valNorm, expNorm)) {
+ cleaned[label] = value as JsonValue;
+ }
+ continue;
+ }
+
+ const diff: JsonObject = {};
+ for (const [field, fieldValue] of Object.entries(valNorm as JsonObject)) {
+ if (!isEqual(fieldValue, (expNorm as JsonObject)[field])) {
+ diff[field] = fieldValue as JsonValue;
+ }
+ }
+ if (Object.keys(diff).length > 0) {
+ cleaned[label] = diff;
+ }
+ }
+ return { ...sourceSection, filters: cleaned };
+}
+
+/**
+ * Strip runtime-only fields from each entry of a dict-of-objects (mask
+ * `enabled_in_config`/`raw_coordinates`, zone `color`) that clone re-injects
+ * from the API.
+ */
+function stripDictEntryFields(
+ dict: unknown,
+ fieldsToStrip: readonly string[],
+): unknown {
+ if (!dict || typeof dict !== "object" || Array.isArray(dict)) return dict;
+ const result: JsonObject = {};
+ for (const [key, value] of Object.entries(dict as JsonObject)) {
+ if (value && typeof value === "object" && !Array.isArray(value)) {
+ const cleaned = { ...(value as JsonObject) };
+ for (const field of fieldsToStrip) {
+ delete cleaned[field];
+ }
+ result[key] = cleaned as JsonValue;
+ } else {
+ result[key] = value as JsonValue;
+ }
+ }
+ return result;
+}
+
+/**
+ * Per-object masks (`objects.filters.<label>.mask`) for the labels that define
+ * one, stripped of runtime fields. The objects form hides `filters.*.mask`, so
+ * clone re-injects these like the camera-wide `objects.mask`.
+ */
+function extractFilterMasks(objectsSection: unknown): JsonObject | undefined {
+ if (!objectsSection || typeof objectsSection !== "object") return undefined;
+ const filters = (objectsSection as JsonObject).filters;
+ if (!filters || typeof filters !== "object" || Array.isArray(filters)) {
+ return undefined;
+ }
+ const result: JsonObject = {};
+ for (const [label, filter] of Object.entries(filters as JsonObject)) {
+ if (!filter || typeof filter !== "object" || Array.isArray(filter))
+ continue;
+ const mask = (filter as JsonObject).mask;
+ if (
+ mask &&
+ typeof mask === "object" &&
+ !Array.isArray(mask) &&
+ Object.keys(mask as JsonObject).length > 0
+ ) {
+ result[label] = {
+ mask: stripDictEntryFields(mask, [
+ "enabled_in_config",
+ "raw_coordinates",
+ ]) as JsonValue,
+ };
+ }
+ }
+ return Object.keys(result).length > 0 ? result : undefined;
+}
+
+/**
+ * Drop `""` (Reset) markers — meaningless for a new camera and unsafe
+ * (backend `update_yaml` raises KeyError trying to `del` a missing key).
+ */
+function stripResetMarkers(
+ value: JsonValue | undefined,
+): JsonValue | undefined {
+ if (value === undefined || value === "") return undefined;
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
+ return value;
+ }
+ const result: JsonObject = {};
+ for (const [key, child] of Object.entries(value as JsonObject)) {
+ const cleaned = stripResetMarkers(child);
+ if (cleaned !== undefined) result[key] = cleaned;
+ }
+ return Object.keys(result).length > 0 ? result : undefined;
+}
+
+/**
+ * Collapse per-section payloads into one camera-level `…/add` payload. The
+ * backend's `add` handler validates atomically, avoiding the per-section
+ * ordering problem (e.g. `review.required_zones` referencing unwritten zones).
+ */
+function bundleNewCameraPayload(
+ payloads: SectionSavePayload[],
+ target: string,
+): SectionSavePayload {
+ const prefix = `cameras.${target}`;
+ const camera: JsonObject = {};
+ for (const p of payloads) {
+ if (p.basePath === prefix) {
+ merge(camera, p.sanitizedOverrides);
+ } else if (p.basePath.startsWith(`${prefix}.`)) {
+ merge(camera, {
+ [p.basePath.slice(prefix.length + 1)]: p.sanitizedOverrides,
+ });
+ }
+ }
+ return {
+ basePath: prefix,
+ sanitizedOverrides: camera,
+ updateTopic: `config/cameras/${target}/add`,
+ needsRestart: true,
+ pendingDataKey: `${target}::add`,
+ };
+}
+
+/**
+ * Drop empty `*_args` arrays from ffmpeg inputs — the establishing payload
+ * uses `buildOverrides` directly, bypassing `sanitizeOverridesForSection`.
+ */
+function cleanupFfmpegInputArgs(
+ ffmpeg: JsonValue | undefined,
+): JsonValue | undefined {
+ if (!ffmpeg || typeof ffmpeg !== "object" || Array.isArray(ffmpeg)) {
+ return ffmpeg;
+ }
+ const obj = ffmpeg as JsonObject;
+ const inputs = obj.inputs;
+ if (!Array.isArray(inputs)) return ffmpeg;
+ const cleanedInputs = inputs.map((input) => {
+ if (!input || typeof input !== "object" || Array.isArray(input))
+ return input;
+ const cleaned = { ...(input as JsonObject) };
+ for (const argsKey of ["global_args", "hwaccel_args", "input_args"]) {
+ const v = cleaned[argsKey];
+ if (Array.isArray(v) && v.length === 0) delete cleaned[argsKey];
+ }
+ return cleaned as JsonValue;
+ });
+ return { ...obj, inputs: cleanedInputs as JsonValue };
+}
+
+/** Subset of `/api/config/raw_paths` used to unmask source credentials. */
+export type RawCameraPaths = {
+ cameras?: Record<
+ string,
+ { ffmpeg?: { inputs?: Array<{ path?: string; roles?: string[] }> } }
+ >;
+};
+
+/**
+ * Replace each ffmpeg input's `path` with the unmasked value from
+ * `rawInputs` at the same index. Mirrors `_restore_masked_camera_paths`.
+ */
+function restoreFfmpegPaths(
+ ffmpeg: unknown,
+ rawInputs: Array<{ path?: string }> | undefined,
+): unknown {
+ if (!ffmpeg || typeof ffmpeg !== "object" || Array.isArray(ffmpeg)) {
+ return ffmpeg;
+ }
+ const obj = cloneDeep(ffmpeg) as JsonObject;
+ const inputs = obj.inputs;
+ if (!Array.isArray(inputs) || !rawInputs) return obj;
+ inputs.forEach((input, i) => {
+ if (!input || typeof input !== "object" || Array.isArray(input)) return;
+ const rawPath = rawInputs[i]?.path;
+ if (typeof rawPath !== "string") return;
+ (input as JsonObject).path = rawPath;
+ });
+ return obj;
+}
+
+/**
+ * Replay the backend's per-camera detect-field formulas on the synthetic
+ * baseline so the source's computed values cancel out of the diff (the global
+ * config has no per-camera derivation).
+ */
+function applyDetectComputedDefaults(
+ detect: JsonObject,
+ fpsOverride?: number,
+): JsonObject {
+ const result = { ...detect };
+ const fps =
+ typeof fpsOverride === "number"
+ ? fpsOverride
+ : typeof result.fps === "number"
+ ? result.fps
+ : 5;
+ if (result.min_initialized == null) {
+ result.min_initialized = Math.max(Math.floor(fps / 2), 2);
+ }
+ if (result.max_disappeared == null) {
+ result.max_disappeared = fps * 5;
+ }
+ const threshold = fps * 10;
+ const stationary = result.stationary;
+ const stat: JsonObject =
+ stationary && typeof stationary === "object" && !Array.isArray(stationary)
+ ? { ...(stationary as JsonObject) }
+ : {};
+ if (stat.threshold == null) stat.threshold = threshold;
+ if (stat.interval == null) stat.interval = threshold;
+ result.stationary = stat as JsonValue;
+ return result;
+}
+
+/**
+ * Categories the dialog exposes. Most map 1:1 to a section config and flow
+ * through `prepareSectionSavePayload`. Special cases:
+ * - `motion_mask`/`object_masks`: carve-outs merged into the parent
+ * section's payload, or emitted standalone if the parent is unselected.
+ * - `ffmpeg_live`: new-camera target only.
+ * - `type`/`profiles`: not schema-driven; built directly below.
+ */
+export type CloneCategoryKey =
+ | "record"
+ | "snapshots"
+ | "review"
+ | "motion"
+ | "objects"
+ | "audio"
+ | "audio_transcription"
+ | "notifications"
+ | "birdseye"
+ | "mqtt"
+ | "timestamp_style"
+ | "onvif"
+ | "lpr"
+ | "face_recognition"
+ | "semantic_search"
+ | "genai"
+ | "type"
+ | "profiles"
+ | "detect"
+ | "zones"
+ | "motion_mask"
+ | "object_masks"
+ | "ffmpeg_live";
+
+export type CloneCategoryGroup = "general" | "spatial" | "streams";
+
+export type CloneCategory = {
+ key: CloneCategoryKey;
+ group: CloneCategoryGroup;
+ /** True when this category is only valid for "new camera" targets. */
+ newCameraOnly?: boolean;
+ /** True when this category is forced selected for new-camera targets. */
+ forcedForNewCamera?: boolean;
+ /** Default selection state for "existing camera" targets when resolutions match. */
+ defaultOnExisting: boolean;
+};
+
+export const CLONE_CATEGORIES: readonly CloneCategory[] = [
+ // General
+ { key: "record", group: "general", defaultOnExisting: true },
+ { key: "snapshots", group: "general", defaultOnExisting: true },
+ { key: "review", group: "general", defaultOnExisting: true },
+ { key: "motion", group: "general", defaultOnExisting: true },
+ { key: "objects", group: "general", defaultOnExisting: true },
+ { key: "audio", group: "general", defaultOnExisting: true },
+ { key: "audio_transcription", group: "general", defaultOnExisting: true },
+ { key: "notifications", group: "general", defaultOnExisting: true },
+ { key: "birdseye", group: "general", defaultOnExisting: true },
+ { key: "mqtt", group: "general", defaultOnExisting: true },
+ { key: "timestamp_style", group: "general", defaultOnExisting: true },
+ { key: "onvif", group: "general", defaultOnExisting: false },
+ { key: "lpr", group: "general", defaultOnExisting: true },
+ { key: "face_recognition", group: "general", defaultOnExisting: true },
+ { key: "semantic_search", group: "general", defaultOnExisting: true },
+ { key: "genai", group: "general", defaultOnExisting: true },
+ { key: "type", group: "general", defaultOnExisting: false },
+ { key: "profiles", group: "general", defaultOnExisting: true },
+ // Spatial — defaults computed via resolutionsMatch()
+ { key: "detect", group: "spatial", defaultOnExisting: true },
+ { key: "zones", group: "spatial", defaultOnExisting: true },
+ { key: "motion_mask", group: "spatial", defaultOnExisting: true },
+ { key: "object_masks", group: "spatial", defaultOnExisting: true },
+ // Streams — only for new-camera target, forced on
+ {
+ key: "ffmpeg_live",
+ group: "streams",
+ newCameraOnly: true,
+ forcedForNewCamera: true,
+ defaultOnExisting: false,
+ },
+] as const;
+
+/**
+ * Exact-match detect dimensions. Aspect-ratio tolerance isn't safe because
+ * zone/mask coords may be stored as explicit pixels, not just 0-1 relative.
+ */
+export function resolutionsMatch(
+ srcDetect: CameraConfig["detect"] | undefined,
+ dstDetect: CameraConfig["detect"] | undefined,
+): boolean {
+ if (!srcDetect || !dstDetect) return false;
+ if (
+ typeof srcDetect.width !== "number" ||
+ typeof srcDetect.height !== "number"
+ ) {
+ return false;
+ }
+ if (
+ typeof dstDetect.width !== "number" ||
+ typeof dstDetect.height !== "number"
+ ) {
+ return false;
+ }
+ return (
+ srcDetect.width === dstDetect.width && srcDetect.height === dstDetect.height
+ );
+}
+
+/**
+ * Initial selection set. Existing-camera targets start empty — copying onto
+ * a configured camera is destructive, so the user opts in explicitly.
+ * New-camera targets pre-select `defaultOnExisting` categories plus
+ * `forcedForNewCamera`.
+ */
+export function getCategoryDefaults(
+ targetIsNew: boolean,
+): Set<CloneCategoryKey> {
+ const selected = new Set<CloneCategoryKey>();
+ if (!targetIsNew) return selected;
+ for (const cat of CLONE_CATEGORIES) {
+ if (cat.forcedForNewCamera || cat.defaultOnExisting) selected.add(cat.key);
+ }
+ return selected;
+}
+
+type BuildClonedPayloadsArgs = {
+ sourceCfg: CameraConfig;
+ sourceName: string;
+ /** Raw user input for new camera, or the existing-camera key. */
+ targetInput: string;
+ targetIsNew: boolean;
+ selectedKeys: Set<CloneCategoryKey>;
+ fullConfig: FrigateConfig;
+ fullSchema: RJSFSchema;
+ rawPaths?: RawCameraPaths;
+};
+
+/**
+ * Build the ordered payloads to PUT. Order: new-camera `…/add`, then
+ * `type` (LPR vs normal affects attribute resolution for later payloads),
+ * then per-section, then `profiles` (no hot-reload topic).
+ */
+export function buildClonedCameraPayloads({
+ sourceCfg,
+ sourceName,
+ targetInput,
+ targetIsNew,
+ selectedKeys,
+ fullConfig,
+ fullSchema,
+ rawPaths,
+}: BuildClonedPayloadsArgs): SectionSavePayload[] {
+ const payloads: SectionSavePayload[] = [];
+
+ const { finalCameraName: target, friendlyName } = targetIsNew
+ ? processCameraName(targetInput)
+ : { finalCameraName: targetInput, friendlyName: undefined };
+
+ // New-camera establishing payload (carries the `…/add` topic).
+ if (targetIsNew) {
+ const addOverrides: Record<string, unknown> = {
+ enabled: true,
+ };
+ if (friendlyName) {
+ addOverrides.friendly_name = friendlyName;
+ }
+ // Diff ffmpeg/live against the global config so fields matching
+ // inherited defaults drop out. Required fields (ffmpeg.inputs) come
+ // along because the source differs from global there.
+ if (selectedKeys.has("ffmpeg_live") && sourceCfg.ffmpeg) {
+ // /api/config masks `user:pass` as `*:*`; backend's restoration
+ // only handles existing cameras, so we unmask here for new ones.
+ const ffmpegWithRealPaths = restoreFfmpegPaths(
+ sourceCfg.ffmpeg,
+ rawPaths?.cameras?.[sourceName]?.ffmpeg?.inputs,
+ );
+ const diff = buildOverrides(
+ ffmpegWithRealPaths,
+ undefined,
+ fullConfig.ffmpeg,
+ );
+ const cleaned = cleanupFfmpegInputArgs(diff as JsonValue | undefined);
+ if (cleaned !== undefined) addOverrides.ffmpeg = cleaned;
+ }
+ if (selectedKeys.has("ffmpeg_live") && sourceCfg.live) {
+ const diff = buildOverrides(
+ sourceCfg.live,
+ undefined,
+ (fullConfig as unknown as JsonObject).live,
+ );
+ if (diff !== undefined) addOverrides.live = diff;
+ }
+ payloads.push({
+ basePath: `cameras.${target}`,
+ sanitizedOverrides: addOverrides as JsonObject,
+ updateTopic: `config/cameras/${target}/add`,
+ needsRestart: true,
+ pendingDataKey: `${target}::__add__`,
+ });
+ }
+
+ // Camera type — top-level scalar, no schema-driven section.
+ if (selectedKeys.has("type")) {
+ const srcType = (sourceCfg as { type?: string | null }).type;
+ if (srcType !== undefined && srcType !== null) {
+ payloads.push({
+ basePath: `cameras.${target}`,
+ sanitizedOverrides: { type: srcType },
+ updateTopic: undefined,
+ needsRestart: true,
+ pendingDataKey: `${target}::type`,
+ });
+ }
+ }
+
+ // Order matters for the existing-camera multi-PUT path (each PUT re-validates
+ // the whole config): `detect` then `zones` must precede sections that
+ // reference zones via `required_zones` (review, objects, snapshots, mqtt).
+ const SECTION_KEYS: Array<{ key: CloneCategoryKey; section: string }> = [
+ { key: "detect", section: "detect" },
+ { key: "zones", section: "zones" },
+ { key: "motion", section: "motion" },
+ { key: "objects", section: "objects" },
+ { key: "record", section: "record" },
+ { key: "snapshots", section: "snapshots" },
+ { key: "review", section: "review" },
+ { key: "audio", section: "audio" },
+ { key: "audio_transcription", section: "audio_transcription" },
+ { key: "notifications", section: "notifications" },
+ { key: "birdseye", section: "birdseye" },
+ { key: "mqtt", section: "mqtt" },
+ { key: "timestamp_style", section: "timestamp_style" },
+ { key: "onvif", section: "onvif" },
+ { key: "lpr", section: "lpr" },
+ { key: "face_recognition", section: "face_recognition" },
+ { key: "semantic_search", section: "semantic_search" },
+ { key: "genai", section: "genai" },
+ ];
+
+ // Synthetic target reused as the diff baseline. New-camera: seed sections
+ // whose camera schema accepts all global fields (correct inheritance
+ // baseline), but leave divergent per-camera sections (mqtt, birdseye, lpr,
+ // face_recognition, semantic_search, audio_transcription, genai) unset —
+ // seeding from global would surface its extra fields as Reset markers.
+ const GLOBAL_INHERITED_SECTIONS = [
+ "detect",
+ "objects",
+ "motion",
+ "record",
+ "snapshots",
+ "review",
+ "audio",
+ "notifications",
+ "ffmpeg",
+ "live",
+ "timestamp_style",
+ ];
+ const syntheticTargetCamera = targetIsNew
+ ? ({
+ enabled: true,
+ ...Object.fromEntries(
+ GLOBAL_INHERITED_SECTIONS.map((s) => [
+ s,
+ cloneDeep((fullConfig as unknown as JsonObject)[s]),
+ ]).filter(([, value]) => value !== undefined && value !== null),
+ ),
+ } as unknown as FrigateConfig["cameras"][string])
+ : ((fullConfig.cameras?.[target]
+ ? cloneDeep(fullConfig.cameras[target])
+ : { enabled: true }) as unknown as FrigateConfig["cameras"][string]);
+
+ // Strip auto-default filters from the baseline (matching the per-section
+ // source strip) so default-only entries cancel. Includes `base_config` (the
+ // pre-profile parse getBaseCameraSectionValue reads) — otherwise its
+ // auto-populated entries become `""` resets and the backend KeyErrors
+ // deleting a key not in the YAML. Cloned above so this won't mutate the cache.
+ const syntheticCameraObj = syntheticTargetCamera as unknown as JsonObject;
+ const baseConfigObj = syntheticCameraObj.base_config as
+ | Record<string, JsonObject>
+ | undefined;
+ for (const section of Object.keys(FILTER_SECTION_DEFS)) {
+ const syntheticSection = syntheticCameraObj[section];
+ if (syntheticSection && typeof syntheticSection === "object") {
+ syntheticCameraObj[section] = stripAutoDefaultFilters(
+ section,
+ syntheticSection as JsonObject,
+ fullSchema,
+ fullConfig,
+ syntheticTargetCamera as CameraConfig,
+ );
+ }
+ const baseSection = baseConfigObj?.[section];
+ if (baseConfigObj && baseSection && typeof baseSection === "object") {
+ baseConfigObj[section] = stripAutoDefaultFilters(
+ section,
+ baseSection,
+ fullSchema,
+ fullConfig,
+ syntheticTargetCamera as CameraConfig,
+ );
+ }
+ }
+
+ // New-camera: synthetic's detect is from global (no per-camera derive),
+ // so apply the formulas using source's fps to keep both sides aligned.
+ // Existing-camera target already has the values from its own parse.
+ if (targetIsNew && sourceCfg.detect) {
+ const syntheticDetect = syntheticCameraObj.detect;
+ if (syntheticDetect && typeof syntheticDetect === "object") {
+ syntheticCameraObj.detect = applyDetectComputedDefaults(
+ syntheticDetect as JsonObject,
+ typeof sourceCfg.detect.fps === "number"
+ ? sourceCfg.detect.fps
+ : undefined,
+ ) as JsonValue;
+ }
+ }
+
+ const syntheticConfig: FrigateConfig = {
+ ...fullConfig,
+ cameras: {
+ ...fullConfig.cameras,
+ [target]: syntheticTargetCamera,
+ },
+ };
+
+ for (const { key, section } of SECTION_KEYS) {
+ if (!selectedKeys.has(key)) continue;
+ const sourceSectionValue = (
+ sourceCfg as unknown as Record<string, unknown>
+ )[section];
+ if (sourceSectionValue == null) continue;
+
+ // Sanitize the source like BaseSection's form does: strip runtime/derived
+ // and hidden-path fields (e.g. `hideAttributeFilters` drops untracked
+ // attributes based on the source's track list).
+ const sectionConfig = getSectionConfig(section, "camera");
+ const resolvedHiddenFields = resolveHiddenFieldEntries(
+ sectionConfig.hiddenFields,
+ {
+ fullConfig,
+ fullCameraConfig: sourceCfg,
+ level: "camera",
+ formData: sourceSectionValue as ConfigSectionData,
+ },
+ );
+ let pendingSectionValue: unknown = sanitizeSectionData(
+ cloneDeep(sourceSectionValue) as ConfigSectionData,
+ resolvedHiddenFields,
+ );
+
+ if (FILTER_SECTION_DEFS[section]) {
+ pendingSectionValue = stripAutoDefaultFilters(
+ section,
+ pendingSectionValue as JsonObject,
+ fullSchema,
+ fullConfig,
+ syntheticTargetCamera as CameraConfig,
+ );
+ }
+
+ // Re-inject masks the parent section's hiddenFields just stripped,
+ // when the mask category is also selected. `raw_mask` is never in
+ // the API response; `enabled_in_config` is runtime-only.
+ if (key === "motion" && selectedKeys.has("motion_mask")) {
+ const srcMask = (sourceSectionValue as { mask?: unknown }).mask;
+ if (srcMask !== undefined) {
+ pendingSectionValue = {
+ ...(pendingSectionValue as object),
+ mask: stripDictEntryFields(srcMask, [
+ "enabled_in_config",
+ "raw_coordinates",
+ ]),
+ };
+ }
+ }
+ if (key === "objects" && selectedKeys.has("object_masks")) {
+ const next = { ...(pendingSectionValue as JsonObject) };
+ // Camera-wide object mask (applies to all objects).
+ const srcMask = (sourceSectionValue as { mask?: unknown }).mask;
+ if (srcMask !== undefined) {
+ next.mask = stripDictEntryFields(srcMask, [
+ "enabled_in_config",
+ "raw_coordinates",
+ ]) as JsonValue;
+ }
+ // Per-object masks (objects.filters.<label>.mask), stripped by the
+ // section's hiddenFields above. Merge them onto the reduced filters
+ // (creating the entry when the filter was otherwise all-default).
+ const filterMasks = extractFilterMasks(sourceSectionValue);
+ if (filterMasks) {
+ const mergedFilters: JsonObject = {
+ ...((next.filters as JsonObject) ?? {}),
+ };
+ for (const [label, overlay] of Object.entries(filterMasks)) {
+ mergedFilters[label] = {
+ ...((mergedFilters[label] as JsonObject) ?? {}),
+ ...(overlay as JsonObject),
+ };
+ }
+ next.filters = mergedFilters;
+ }
+ pendingSectionValue = next;
+ }
+
+ // `color` is a Pydantic PrivateAttr (runtime-only).
+ if (key === "zones") {
+ pendingSectionValue = stripDictEntryFields(pendingSectionValue, [
+ "color",
+ ]);
+ }
+
+ const payload = prepareSectionSavePayload({
+ pendingDataKey: `${target}::${section}`,
+ pendingData: pendingSectionValue,
+ config: syntheticConfig,
+ fullSchema,
+ });
+ if (payload) {
+ payloads.push(payload);
+ }
+ }
+
+ // Standalone mask payloads — only when the parent section isn't also
+ // selected (otherwise the masks were merged into its payload above).
+ if (selectedKeys.has("motion_mask") && !selectedKeys.has("motion")) {
+ const srcMask = (sourceCfg.motion as { mask?: unknown } | undefined)?.mask;
+ if (srcMask !== undefined) {
+ payloads.push({
+ basePath: `cameras.${target}.motion`,
+ sanitizedOverrides: {
+ mask: stripDictEntryFields(srcMask, [
+ "enabled_in_config",
+ "raw_coordinates",
+ ]) as JsonValue,
+ },
+ updateTopic: `config/cameras/${target}/${cameraUpdateTopicMap.motion}`,
+ needsRestart: false,
+ pendingDataKey: `${target}::motion.masks`,
+ });
+ }
+ }
+ if (selectedKeys.has("object_masks") && !selectedKeys.has("objects")) {
+ const overrides: JsonObject = {};
+ const srcMask = (sourceCfg.objects as { mask?: unknown } | undefined)?.mask;
+ if (srcMask !== undefined) {
+ overrides.mask = stripDictEntryFields(srcMask, [
+ "enabled_in_config",
+ "raw_coordinates",
+ ]) as JsonValue;
+ }
+ const filterMasks = extractFilterMasks(sourceCfg.objects);
+ if (filterMasks) {
+ overrides.filters = filterMasks;
+ }
+ if (Object.keys(overrides).length > 0) {
+ payloads.push({
+ basePath: `cameras.${target}.objects`,
+ sanitizedOverrides: overrides,
+ updateTopic: `config/cameras/${target}/${cameraUpdateTopicMap.objects}`,
+ needsRestart: false,
+ pendingDataKey: `${target}::objects.masks`,
+ });
+ }
+ }
+
+ // Profiles — wholesale dict replacement; no hot-reload topic.
+ if (selectedKeys.has("profiles")) {
+ const srcProfiles = (sourceCfg as { profiles?: unknown }).profiles;
+ if (srcProfiles && typeof srcProfiles === "object") {
+ payloads.push({
+ basePath: `cameras.${target}.profiles`,
+ sanitizedOverrides: cloneDeep(srcProfiles) as JsonObject,
+ updateTopic: undefined,
+ needsRestart: true,
+ pendingDataKey: `${target}::profiles`,
+ });
+ }
+ }
+
+ // New camera: scrub Reset markers (see stripResetMarkers), then bundle
+ // into one atomic `…/add` PUT so the backend validates the full camera
+ // at once (avoids per-section ordering issues).
+ if (targetIsNew) {
+ const scrubbed = payloads
+ .map((p) => {
+ const cleaned = stripResetMarkers(p.sanitizedOverrides as JsonValue);
+ return cleaned === undefined
+ ? null
+ : { ...p, sanitizedOverrides: cleaned as JsonObject };
+ })
+ .filter((p): p is SectionSavePayload => p !== null);
+ return [bundleNewCameraPayload(scrubbed, target)];
+ }
+
+ return payloads;
+}
+
+/**
+ * Flatten payloads to `SaveAllPreviewItem`s with camera-relative
+ * `fieldPath`s (matches BaseSection's per-section preview).
+ */
+export function buildClonePreviewItems(
+ payloads: SectionSavePayload[],
+ targetCamera: string,
+): SaveAllPreviewItem[] {
+ const cameraBase = `cameras.${targetCamera}`;
+ return payloads.flatMap((p) => {
+ const flattened = flattenOverrides(p.sanitizedOverrides as JsonValue);
+ const sectionRelativeBase =
+ p.basePath === cameraBase
+ ? ""
+ : p.basePath.startsWith(`${cameraBase}.`)
+ ? p.basePath.slice(cameraBase.length + 1)
+ : p.basePath;
+ return flattened.map(({ path, value }) => ({
+ scope: "camera" as const,
+ cameraName: targetCamera,
+ fieldPath: path
+ ? sectionRelativeBase
+ ? `${sectionRelativeBase}.${path}`
+ : path
+ : sectionRelativeBase,
+ value,
+ }));
+ });
+}
diff --git a/web/src/utils/configUtil.ts b/web/src/utils/configUtil.ts
index 3ebe96a63b..6593c95a3a 100644
--- a/web/src/utils/configUtil.ts
+++ b/web/src/utils/configUtil.ts
@@ -81,6 +81,7 @@ export const cameraUpdateTopicMap: Record<string, string> = {
mqtt: "mqtt",
onvif: "onvif",
ui: "ui",
+ zones: "zones",
};
// Sections where global config serves as the default for per-camera config.
diff --git a/web/src/views/settings/CameraManagementView.tsx b/web/src/views/settings/CameraManagementView.tsx
index f18b8f94b4..96ac321362 100644
--- a/web/src/views/settings/CameraManagementView.tsx
+++ b/web/src/views/settings/CameraManagementView.tsx
@@ -1,12 +1,18 @@
import Heading from "@/components/ui/heading";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import {
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import {
CONTROL_COLUMN_CLASS_NAME,
SettingsGroupCard,
SPLIT_ROW_CLASS_NAME,
} from "@/components/card/SettingsGroupCard";
import { toast } from "sonner";
-import { Toaster } from "@/components/ui/sonner";
import { Button } from "@/components/ui/button";
import useSWR from "swr";
import { FrigateConfig } from "@/types/frigateConfig";
@@ -15,6 +21,7 @@ import CameraWizardDialog from "@/components/settings/CameraWizardDialog";
import DeleteCameraDialog from "@/components/overlay/dialog/DeleteCameraDialog";
import {
LuCheck,
+ LuCopy,
LuExternalLink,
LuGripVertical,
LuPencil,
@@ -22,6 +29,7 @@ import {
LuRefreshCcw,
LuTrash2,
} from "react-icons/lu";
+import CloneCameraDialog from "@/components/settings/CloneCameraDialog";
import { Reorder, useDragControls } from "framer-motion";
import { Link } from "react-router-dom";
import { useDocDomain } from "@/hooks/use-doc-domain";
@@ -50,6 +58,7 @@ import {
import type { ProfileState } from "@/types/profile";
import { getProfileColor } from "@/utils/profileColors";
import { isReplayCamera } from "@/utils/cameraUtil";
+import { StatusBarMessagesContext } from "@/context/statusbar-provider";
import { cn } from "@/lib/utils";
import {
Select,
@@ -88,6 +97,7 @@ export default function CameraManagementView({
const [showWizard, setShowWizard] = useState(false);
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
+ const [showCloneDialog, setShowCloneDialog] = useState(false);
// State for restart dialog when enabling a disabled camera
const [restartDialogOpen, setRestartDialogOpen] = useState(false);
@@ -217,12 +227,6 @@ export default function CameraManagementView({
return (
<>
- <Toaster
- richColors
- className="z-[1000]"
- position="top-center"
- closeButton
- />
<div className="flex size-full space-y-6">
<div className="scrollbar-container flex-1 overflow-y-auto pb-2">
<Heading as="h4" className="mb-2">
@@ -254,6 +258,27 @@ export default function CameraManagementView({
)}
</div>
+ {enabledCameras.length + disabledCameras.length > 0 && (
+ <div className="mb-5 space-y-3">
+ <div className="space-y-0.5">
+ <div className="text-md font-medium">
+ {t("cameraManagement.clone.sectionTitle")}
+ </div>
+ <p className="text-sm text-muted-foreground">
+ {t("cameraManagement.clone.sectionDescription")}
+ </p>
+ </div>
+ <Button
+ variant="select"
+ onClick={() => setShowCloneDialog(true)}
+ className="flex max-w-48 items-center gap-2"
+ >
+ <LuCopy className="h-4 w-4" />
+ {t("cameraManagement.clone.button")}
+ </Button>
+ </div>
+ )}
+
{(enabledCameras.length > 0 || disabledCameras.length > 0) && (
<SettingsGroupCard
title={
@@ -364,6 +389,10 @@ export default function CameraManagementView({
onClose={() => setRestartDialogOpen(false)}
onRestart={() => sendRestart("restart")}
/>
+ <CloneCameraDialog
+ open={showCloneDialog}
+ onClose={() => setShowCloneDialog(false)}
+ />
</>
);
}
@@ -501,6 +530,7 @@ function CameraStatusSelect({
]);
const { payload: enabledState, send: sendEnabled } =
useEnabledState(cameraName);
+ const statusBar = useContext(StatusBarMessagesContext);
const [isSaving, setIsSaving] = useState(false);
const currentStatus: CameraStatus = isDisabledInConfig
@@ -586,6 +616,12 @@ function CameraStatusSelect({
},
});
await onConfigChanged();
+ statusBar?.addMessage(
+ "config_restart_required",
+ t("configForm.restartRequiredFooter", { ns: "views/settings" }),
+ undefined,
+ "config_restart_required",
+ );
toast.success(
t("cameraManagement.streams.disableSuccess", {
ns: "views/settings",
@@ -617,6 +653,7 @@ function CameraStatusSelect({
onConfigChanged,
sendEnabled,
setRestartDialogOpen,
+ statusBar,
t,
],
);