mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-09 15:05:26 +03:00
Compare commits
1 Commits
d6f962bb7b
...
e571a1bdb1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e571a1bdb1 |
@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)
|
|||||||
RECORDING_BUFFER_EXTENSION_PERCENT = 0.10
|
RECORDING_BUFFER_EXTENSION_PERCENT = 0.10
|
||||||
MIN_RECORDING_DURATION = 10
|
MIN_RECORDING_DURATION = 10
|
||||||
MAX_IMAGE_TOKENS = 24000
|
MAX_IMAGE_TOKENS = 24000
|
||||||
MAX_FRAMES_PER_SECOND = 1
|
MAX_FRAMES_PER_SECOND = 2
|
||||||
|
|
||||||
|
|
||||||
class ReviewDescriptionProcessor(PostProcessorApi):
|
class ReviewDescriptionProcessor(PostProcessorApi):
|
||||||
|
|||||||
@ -1,48 +1,25 @@
|
|||||||
from typing import Annotated
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field, StringConstraints
|
|
||||||
|
|
||||||
ObservationItem = Annotated[str, StringConstraints(min_length=20, max_length=160)]
|
|
||||||
|
|
||||||
|
|
||||||
class ReviewMetadata(BaseModel):
|
class ReviewMetadata(BaseModel):
|
||||||
model_config = ConfigDict(extra="ignore", protected_namespaces=())
|
model_config = ConfigDict(extra="ignore", protected_namespaces=())
|
||||||
|
|
||||||
observations: list[ObservationItem] = Field(
|
observations: list[str] = Field(
|
||||||
...,
|
default_factory=list,
|
||||||
min_length=3,
|
description="Chronological list of significant observations from the frames, written before the scene narrative is composed.",
|
||||||
max_length=15,
|
|
||||||
description=(
|
|
||||||
"Enumerate the significant observations across all frames, in "
|
|
||||||
"chronological order, BEFORE composing the scene narrative. "
|
|
||||||
"Include the very start of the activity — for example, a vehicle "
|
|
||||||
"entering the frame or pulling into the driveway — even if it "
|
|
||||||
"lasts only a few frames and the rest of the clip is dominated "
|
|
||||||
"by a longer activity. Include each arrival, departure, motion "
|
|
||||||
"event, object handled, and notable change in position or state. "
|
|
||||||
"Each item is a single concrete fact written as a complete "
|
|
||||||
"sentence. Do not summarize, interpret, or assign meaning here — "
|
|
||||||
"that belongs in the scene field."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
title: str = Field(
|
title: str = Field(
|
||||||
max_length=80,
|
description="A short title characterizing what took place and where, under 10 words."
|
||||||
description="A short title characterizing what took place and where, under 10 words.",
|
|
||||||
)
|
)
|
||||||
scene: str = Field(
|
scene: str = Field(
|
||||||
min_length=150,
|
description="A chronological narrative of what happens from start to finish.",
|
||||||
max_length=600,
|
|
||||||
description="A chronological narrative of what happens from start to finish, drawing directly from the items in observations.",
|
|
||||||
)
|
)
|
||||||
shortSummary: str = Field(
|
shortSummary: str = Field(
|
||||||
min_length=70,
|
description="A brief 2-sentence summary of the scene, suitable for notifications."
|
||||||
max_length=100,
|
|
||||||
description="A brief 2-sentence summary of the scene, suitable for notifications.",
|
|
||||||
)
|
)
|
||||||
confidence: float = Field(
|
confidence: float = Field(
|
||||||
ge=0.0,
|
ge=0.0,
|
||||||
le=1.0,
|
description="Confidence in the analysis, from 0 to 1.",
|
||||||
description="Confidence in the analysis as a decimal between 0.0 and 1.0, where 0.0 means no confidence and 1.0 means complete confidence. Express ONLY as a decimal.",
|
|
||||||
)
|
)
|
||||||
potential_threat_level: int = Field(
|
potential_threat_level: int = Field(
|
||||||
ge=0,
|
ge=0,
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import importlib
|
import importlib
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -10,7 +9,6 @@ from typing import Any, Callable, Optional
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
from pydantic import ValidationError
|
|
||||||
|
|
||||||
from frigate.config import CameraConfig, GenAIConfig, GenAIProviderEnum
|
from frigate.config import CameraConfig, GenAIConfig, GenAIProviderEnum
|
||||||
from frigate.const import CLIPS_DIR
|
from frigate.const import CLIPS_DIR
|
||||||
@ -153,6 +151,50 @@ Each line represents a detection state, not necessarily unique individuals. The
|
|||||||
if "other_concerns" in schema.get("required", []):
|
if "other_concerns" in schema.get("required", []):
|
||||||
schema["required"].remove("other_concerns")
|
schema["required"].remove("other_concerns")
|
||||||
|
|
||||||
|
# Length hints injected into the schema as suggestions to the model
|
||||||
|
# (enforced by grammar-based providers like llama.cpp) but kept off the
|
||||||
|
# Pydantic model so a non-compliant response does not fail validation.
|
||||||
|
length_hints = {
|
||||||
|
"scene": {"minLength": 120, "maxLength": 600},
|
||||||
|
"shortSummary": {"minLength": 70, "maxLength": 100},
|
||||||
|
}
|
||||||
|
for field, hints in length_hints.items():
|
||||||
|
prop = schema.get("properties", {}).get(field)
|
||||||
|
if prop is not None:
|
||||||
|
prop.update(hints)
|
||||||
|
|
||||||
|
# observations is a chain-of-thought-by-schema field: forcing the model
|
||||||
|
# to enumerate concrete facts before writing scene/title surfaces details
|
||||||
|
# the narrative would otherwise gloss past (e.g. brief vehicle arrivals
|
||||||
|
# overshadowed by a longer activity). The minItems floor scales with
|
||||||
|
# event duration so longer clips get more observations.
|
||||||
|
observations_prop = schema.get("properties", {}).get("observations")
|
||||||
|
if observations_prop is not None:
|
||||||
|
duration_seconds = float(review_data.get("duration") or 0)
|
||||||
|
min_observations = max(3, round(duration_seconds / 5))
|
||||||
|
max_observations = min_observations + 8
|
||||||
|
observations_prop["description"] = (
|
||||||
|
"Enumerate the significant observations across all frames, in "
|
||||||
|
"chronological order, BEFORE composing the scene narrative. "
|
||||||
|
"Include the very start of the activity — for example, a "
|
||||||
|
"vehicle entering the frame or pulling into the driveway — "
|
||||||
|
"even if it lasts only a few frames and the rest of the clip "
|
||||||
|
"is dominated by a longer activity. Include each arrival, "
|
||||||
|
"departure, motion event, object handled, and notable change "
|
||||||
|
"in position or state. Each item is a single concrete fact "
|
||||||
|
"written as a complete sentence (e.g., 'A blue sedan turns "
|
||||||
|
"from the street into the driveway', 'Nick exits the driver "
|
||||||
|
"side carrying a plant pot'). Do not summarize, interpret, or "
|
||||||
|
"assign meaning here — that belongs in the scene field."
|
||||||
|
)
|
||||||
|
observations_prop["minItems"] = min_observations
|
||||||
|
observations_prop["maxItems"] = max_observations
|
||||||
|
observations_prop["items"] = {"type": "string", "minLength": 20}
|
||||||
|
|
||||||
|
required = schema.setdefault("required", [])
|
||||||
|
if "observations" not in required:
|
||||||
|
required.append("observations")
|
||||||
|
|
||||||
# OpenAI strict mode requires additionalProperties: false on all objects
|
# OpenAI strict mode requires additionalProperties: false on all objects
|
||||||
schema["additionalProperties"] = False
|
schema["additionalProperties"] = False
|
||||||
|
|
||||||
@ -183,35 +225,7 @@ Each line represents a detection state, not necessarily unique individuals. The
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
metadata = ReviewMetadata.model_validate_json(clean_json)
|
metadata = ReviewMetadata.model_validate_json(clean_json)
|
||||||
except ValidationError as ve:
|
|
||||||
# Constraint violations (length, item count, ranges) are logged
|
|
||||||
# at debug and the response is kept anyway — a slightly
|
|
||||||
# off-spec answer is still usable, and dropping the whole
|
|
||||||
# response loses the narrative content the model produced.
|
|
||||||
for err in ve.errors():
|
|
||||||
loc = ".".join(str(p) for p in err["loc"]) or "<root>"
|
|
||||||
logger.debug(
|
|
||||||
"Review metadata soft validation: %s — %s (input: %r)",
|
|
||||||
loc,
|
|
||||||
err["msg"],
|
|
||||||
err.get("input"),
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
raw = json.loads(clean_json)
|
|
||||||
except json.JSONDecodeError as je:
|
|
||||||
logger.error("Failed to parse review description JSON: %s", je)
|
|
||||||
return None
|
|
||||||
# observations is required on the model; fill an empty default
|
|
||||||
# if the response omitted it so attribute access stays safe.
|
|
||||||
raw.setdefault("observations", [])
|
|
||||||
metadata = ReviewMetadata.model_construct(**raw)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
f"Failed to parse review description as the response did not match expected format. {e}"
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Normalize confidence if model returned a percentage (e.g. 85 instead of 0.85)
|
# Normalize confidence if model returned a percentage (e.g. 85 instead of 0.85)
|
||||||
if metadata.confidence > 1.0:
|
if metadata.confidence > 1.0:
|
||||||
metadata.confidence = min(metadata.confidence / 100.0, 1.0)
|
metadata.confidence = min(metadata.confidence / 100.0, 1.0)
|
||||||
@ -224,7 +238,10 @@ Each line represents a detection state, not necessarily unique individuals. The
|
|||||||
metadata.time = review_data["start"]
|
metadata.time = review_data["start"]
|
||||||
return metadata
|
return metadata
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to post-process review metadata: {e}")
|
# rarely LLMs can fail to follow directions on output format
|
||||||
|
logger.warning(
|
||||||
|
f"Failed to parse review description as the response did not match expected format. {e}"
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|||||||
@ -457,13 +457,7 @@
|
|||||||
"enableDesc": "Temporarily disable an enabled camera until Frigate restarts. Disabling a camera completely stops Frigate's processing of this camera's streams. Detection, recording, and debugging will be unavailable.<br /> <em>Note: This does not disable go2rtc restreams.</em>",
|
"enableDesc": "Temporarily disable an enabled camera until Frigate restarts. Disabling a camera completely stops Frigate's processing of this camera's streams. Detection, recording, and debugging will be unavailable.<br /> <em>Note: This does not disable go2rtc restreams.</em>",
|
||||||
"disableLabel": "Disabled cameras",
|
"disableLabel": "Disabled cameras",
|
||||||
"disableDesc": "Enable a camera that is currently not visible in the UI and disabled in the configuration. A restart of Frigate is required after enabling.",
|
"disableDesc": "Enable a camera that is currently not visible in the UI and disabled in the configuration. A restart of Frigate is required after enabling.",
|
||||||
"enableSuccess": "Enabled {{cameraName}} in configuration. Restart Frigate to apply the changes.",
|
"enableSuccess": "Enabled {{cameraName}} in configuration. Restart Frigate to apply the changes."
|
||||||
"friendlyName": {
|
|
||||||
"edit": "Edit camera display name",
|
|
||||||
"title": "Edit Display Name",
|
|
||||||
"description": "Set the friendly name shown for this camera throughout the Frigate UI. Leave blank to use the camera ID.",
|
|
||||||
"rename": "Rename"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"cameraConfig": {
|
"cameraConfig": {
|
||||||
"add": "Add Camera",
|
"add": "Add Camera",
|
||||||
|
|||||||
@ -65,14 +65,10 @@ import {
|
|||||||
globalCameraDefaultSections,
|
globalCameraDefaultSections,
|
||||||
buildOverrides,
|
buildOverrides,
|
||||||
buildConfigDataForPath,
|
buildConfigDataForPath,
|
||||||
flattenOverrides,
|
|
||||||
getBaseCameraSectionValue,
|
getBaseCameraSectionValue,
|
||||||
sanitizeSectionData as sharedSanitizeSectionData,
|
sanitizeSectionData as sharedSanitizeSectionData,
|
||||||
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
||||||
} from "@/utils/configUtil";
|
} from "@/utils/configUtil";
|
||||||
import SaveAllPreviewPopover, {
|
|
||||||
type SaveAllPreviewItem,
|
|
||||||
} from "@/components/overlay/detail/SaveAllPreviewPopover";
|
|
||||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||||
import { useRestart } from "@/api/ws";
|
import { useRestart } from "@/api/ws";
|
||||||
import type {
|
import type {
|
||||||
@ -917,34 +913,6 @@ export function ConfigSection({
|
|||||||
);
|
);
|
||||||
}, [sectionConfig?.renderers, sectionPath, cameraName, setPendingData]);
|
}, [sectionConfig?.renderers, sectionPath, cameraName, setPendingData]);
|
||||||
|
|
||||||
// Build a flat list of pending field changes for this section only.
|
|
||||||
// Mirrors the global Save All preview but scoped to the current section so
|
|
||||||
// users can inspect what will be saved without leaving the section.
|
|
||||||
const sectionPreviewItems = useMemo<SaveAllPreviewItem[]>(() => {
|
|
||||||
if (!hasChanges) return [];
|
|
||||||
if (!effectiveOverrides || typeof effectiveOverrides !== "object") {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const flattened = flattenOverrides(effectiveOverrides as JsonValue);
|
|
||||||
return flattened.map(({ path, value }) => ({
|
|
||||||
scope: effectiveLevel,
|
|
||||||
cameraName,
|
|
||||||
profileName: profileName
|
|
||||||
? (profileFriendlyName ?? profileName)
|
|
||||||
: undefined,
|
|
||||||
fieldPath: path ? `${sectionPath}.${path}` : sectionPath,
|
|
||||||
value,
|
|
||||||
}));
|
|
||||||
}, [
|
|
||||||
hasChanges,
|
|
||||||
effectiveOverrides,
|
|
||||||
effectiveLevel,
|
|
||||||
cameraName,
|
|
||||||
profileName,
|
|
||||||
profileFriendlyName,
|
|
||||||
sectionPath,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!modifiedSchema) {
|
if (!modifiedSchema) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1050,12 +1018,6 @@ export function ConfigSection({
|
|||||||
defaultValue: "You have unsaved changes",
|
defaultValue: "You have unsaved changes",
|
||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
<SaveAllPreviewPopover
|
|
||||||
items={sectionPreviewItems}
|
|
||||||
className="h-7 w-7"
|
|
||||||
align="start"
|
|
||||||
side="top"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex w-full flex-col gap-2 sm:flex-row sm:items-center md:w-auto">
|
<div className="flex w-full flex-col gap-2 sm:flex-row sm:items-center md:w-auto">
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
|
||||||
import TextEntry from "@/components/input/TextEntry";
|
import TextEntry from "@/components/input/TextEntry";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@ -20,9 +19,7 @@ type TextEntryDialogProps = {
|
|||||||
setOpen: (open: boolean) => void;
|
setOpen: (open: boolean) => void;
|
||||||
onSave: (text: string) => void;
|
onSave: (text: string) => void;
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
placeholder?: string;
|
|
||||||
allowEmpty?: boolean;
|
allowEmpty?: boolean;
|
||||||
isSaving?: boolean;
|
|
||||||
regexPattern?: RegExp;
|
regexPattern?: RegExp;
|
||||||
regexErrorMessage?: string;
|
regexErrorMessage?: string;
|
||||||
forbiddenPattern?: RegExp;
|
forbiddenPattern?: RegExp;
|
||||||
@ -36,9 +33,7 @@ export default function TextEntryDialog({
|
|||||||
setOpen,
|
setOpen,
|
||||||
onSave,
|
onSave,
|
||||||
defaultValue = "",
|
defaultValue = "",
|
||||||
placeholder,
|
|
||||||
allowEmpty = false,
|
allowEmpty = false,
|
||||||
isSaving = false,
|
|
||||||
regexPattern,
|
regexPattern,
|
||||||
regexErrorMessage,
|
regexErrorMessage,
|
||||||
forbiddenPattern,
|
forbiddenPattern,
|
||||||
@ -55,7 +50,6 @@ export default function TextEntryDialog({
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<TextEntry
|
<TextEntry
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
placeholder={placeholder}
|
|
||||||
allowEmpty={allowEmpty}
|
allowEmpty={allowEmpty}
|
||||||
onSave={onSave}
|
onSave={onSave}
|
||||||
regexPattern={regexPattern}
|
regexPattern={regexPattern}
|
||||||
@ -64,22 +58,11 @@ export default function TextEntryDialog({
|
|||||||
forbiddenErrorMessage={forbiddenErrorMessage}
|
forbiddenErrorMessage={forbiddenErrorMessage}
|
||||||
>
|
>
|
||||||
<DialogFooter className={cn("pt-4", isMobile && "gap-2")}>
|
<DialogFooter className={cn("pt-4", isMobile && "gap-2")}>
|
||||||
<Button
|
<Button type="button" onClick={() => setOpen(false)}>
|
||||||
type="button"
|
|
||||||
disabled={isSaving}
|
|
||||||
onClick={() => setOpen(false)}
|
|
||||||
>
|
|
||||||
{t("button.cancel")}
|
{t("button.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="select" type="submit" disabled={isSaving}>
|
<Button variant="select" type="submit">
|
||||||
{isSaving ? (
|
{t("button.save")}
|
||||||
<div className="flex flex-row items-center gap-2">
|
|
||||||
<ActivityIndicator className="size-4" />
|
|
||||||
<span>{t("button.saving")}</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
t("button.save")
|
|
||||||
)}
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</TextEntry>
|
</TextEntry>
|
||||||
|
|||||||
@ -28,7 +28,11 @@ import useOptimisticState from "@/hooks/use-optimistic-state";
|
|||||||
import { isMobile } from "react-device-detect";
|
import { isMobile } from "react-device-detect";
|
||||||
import { FaVideo } from "react-icons/fa";
|
import { FaVideo } from "react-icons/fa";
|
||||||
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
||||||
import type { ConfigSectionData, JsonObject } from "@/types/configForm";
|
import type {
|
||||||
|
ConfigSectionData,
|
||||||
|
JsonObject,
|
||||||
|
JsonValue,
|
||||||
|
} from "@/types/configForm";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import FilterSwitch from "@/components/filter/FilterSwitch";
|
import FilterSwitch from "@/components/filter/FilterSwitch";
|
||||||
import { ZoneMaskFilterButton } from "@/components/filter/ZoneMaskFilter";
|
import { ZoneMaskFilterButton } from "@/components/filter/ZoneMaskFilter";
|
||||||
@ -89,7 +93,6 @@ import { mutate } from "swr";
|
|||||||
import { RJSFSchema } from "@rjsf/utils";
|
import { RJSFSchema } from "@rjsf/utils";
|
||||||
import {
|
import {
|
||||||
buildConfigDataForPath,
|
buildConfigDataForPath,
|
||||||
flattenOverrides,
|
|
||||||
parseProfileFromSectionPath,
|
parseProfileFromSectionPath,
|
||||||
prepareSectionSavePayload,
|
prepareSectionSavePayload,
|
||||||
PROFILE_ELIGIBLE_SECTIONS,
|
PROFILE_ELIGIBLE_SECTIONS,
|
||||||
@ -187,6 +190,25 @@ const parsePendingDataKey = (pendingDataKey: string) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const flattenOverrides = (
|
||||||
|
value: JsonValue | undefined,
|
||||||
|
path: string[] = [],
|
||||||
|
): Array<{ path: string; value: JsonValue }> => {
|
||||||
|
if (value === undefined) return [];
|
||||||
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||||
|
return [{ path: path.join("."), value }];
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = Object.entries(value);
|
||||||
|
if (entries.length === 0) {
|
||||||
|
return [{ path: path.join("."), value: {} }];
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries.flatMap(([key, entryValue]) =>
|
||||||
|
flattenOverrides(entryValue, [...path, key]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const createSectionPage = (
|
const createSectionPage = (
|
||||||
sectionKey: string,
|
sectionKey: string,
|
||||||
level: "global" | "camera",
|
level: "global" | "camera",
|
||||||
|
|||||||
@ -219,32 +219,6 @@ export function buildOverrides(
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// flattenOverrides — turn an overrides object into a list of leaf paths
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Walks a nested overrides value and produces a flat list of `{ path, value }`
|
|
||||||
// entries, one per leaf. Used by save/preview UIs to enumerate the individual
|
|
||||||
// fields that will be changed.
|
|
||||||
export function flattenOverrides(
|
|
||||||
value: JsonValue | undefined,
|
|
||||||
path: string[] = [],
|
|
||||||
): Array<{ path: string; value: JsonValue }> {
|
|
||||||
if (value === undefined) return [];
|
|
||||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
||||||
return [{ path: path.join("."), value }];
|
|
||||||
}
|
|
||||||
|
|
||||||
const entries = Object.entries(value);
|
|
||||||
if (entries.length === 0) {
|
|
||||||
return [{ path: path.join("."), value: {} }];
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries.flatMap(([key, entryValue]) =>
|
|
||||||
flattenOverrides(entryValue, [...path, key]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// sanitizeSectionData — normalize config values and strip hidden fields
|
// sanitizeSectionData — normalize config values and strip hidden fields
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import CameraEditForm from "@/components/settings/CameraEditForm";
|
import CameraEditForm from "@/components/settings/CameraEditForm";
|
||||||
import CameraWizardDialog from "@/components/settings/CameraWizardDialog";
|
import CameraWizardDialog from "@/components/settings/CameraWizardDialog";
|
||||||
import DeleteCameraDialog from "@/components/overlay/dialog/DeleteCameraDialog";
|
import DeleteCameraDialog from "@/components/overlay/dialog/DeleteCameraDialog";
|
||||||
import { LuPencil, LuPlus, LuTrash2 } from "react-icons/lu";
|
import { LuPlus, LuTrash2 } from "react-icons/lu";
|
||||||
import { IoMdArrowRoundBack } from "react-icons/io";
|
import { IoMdArrowRoundBack } from "react-icons/io";
|
||||||
import { isDesktop } from "react-device-detect";
|
import { isDesktop } from "react-device-detect";
|
||||||
import { CameraNameLabel } from "@/components/camera/FriendlyNameLabel";
|
import { CameraNameLabel } from "@/components/camera/FriendlyNameLabel";
|
||||||
@ -26,12 +26,6 @@ import axios from "axios";
|
|||||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||||
import RestartRequiredIndicator from "@/components/indicators/RestartRequiredIndicator";
|
import RestartRequiredIndicator from "@/components/indicators/RestartRequiredIndicator";
|
||||||
import TextEntryDialog from "@/components/overlay/dialog/TextEntryDialog";
|
|
||||||
import {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip";
|
|
||||||
import type { ProfileState } from "@/types/profile";
|
import type { ProfileState } from "@/types/profile";
|
||||||
import { getProfileColor } from "@/utils/profileColors";
|
import { getProfileColor } from "@/utils/profileColors";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@ -167,13 +161,7 @@ export default function CameraManagementView({
|
|||||||
key={camera}
|
key={camera}
|
||||||
className="flex flex-row items-center justify-between"
|
className="flex flex-row items-center justify-between"
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<CameraNameLabel camera={camera} />
|
<CameraNameLabel camera={camera} />
|
||||||
<CameraFriendlyNameEditor
|
|
||||||
cameraName={camera}
|
|
||||||
onConfigChanged={updateConfig}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<CameraEnableSwitch cameraName={camera} />
|
<CameraEnableSwitch cameraName={camera} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@ -309,103 +297,6 @@ function CameraEnableSwitch({ cameraName }: CameraEnableSwitchProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type CameraFriendlyNameEditorProps = {
|
|
||||||
cameraName: string;
|
|
||||||
onConfigChanged: () => Promise<unknown>;
|
|
||||||
};
|
|
||||||
|
|
||||||
function CameraFriendlyNameEditor({
|
|
||||||
cameraName,
|
|
||||||
onConfigChanged,
|
|
||||||
}: CameraFriendlyNameEditorProps) {
|
|
||||||
const { t } = useTranslation(["views/settings", "common"]);
|
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
|
||||||
|
|
||||||
const currentFriendlyName = config?.cameras?.[cameraName]?.friendly_name;
|
|
||||||
|
|
||||||
const onSave = useCallback(
|
|
||||||
async (text: string) => {
|
|
||||||
if (isSaving) return;
|
|
||||||
setIsSaving(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await axios.put("config/set", {
|
|
||||||
requires_restart: 0,
|
|
||||||
config_data: {
|
|
||||||
cameras: {
|
|
||||||
[cameraName]: {
|
|
||||||
friendly_name: text.trim() || null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await onConfigChanged();
|
|
||||||
setOpen(false);
|
|
||||||
|
|
||||||
toast.success(t("toast.save.success", { ns: "common" }), {
|
|
||||||
position: "top-center",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
const errorMessage =
|
|
||||||
axios.isAxiosError(error) &&
|
|
||||||
(error.response?.data?.message || error.response?.data?.detail)
|
|
||||||
? error.response?.data?.message || error.response?.data?.detail
|
|
||||||
: t("toast.save.error.noMessage", { ns: "common" });
|
|
||||||
|
|
||||||
toast.error(
|
|
||||||
t("toast.save.error.title", { errorMessage, ns: "common" }),
|
|
||||||
{ position: "top-center" },
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
setIsSaving(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[cameraName, isSaving, onConfigChanged, t],
|
|
||||||
);
|
|
||||||
|
|
||||||
const renameLabel = t("cameraManagement.streams.friendlyName.rename", {
|
|
||||||
ns: "views/settings",
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="size-7"
|
|
||||||
aria-label={renameLabel}
|
|
||||||
onClick={() => setOpen(true)}
|
|
||||||
disabled={isSaving}
|
|
||||||
>
|
|
||||||
<LuPencil className="size-3.5" />
|
|
||||||
</Button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>{renameLabel}</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
<TextEntryDialog
|
|
||||||
open={open}
|
|
||||||
setOpen={setOpen}
|
|
||||||
title={t("cameraManagement.streams.friendlyName.title", {
|
|
||||||
ns: "views/settings",
|
|
||||||
})}
|
|
||||||
description={t("cameraManagement.streams.friendlyName.description", {
|
|
||||||
ns: "views/settings",
|
|
||||||
})}
|
|
||||||
defaultValue={currentFriendlyName ?? ""}
|
|
||||||
placeholder={currentFriendlyName ? undefined : cameraName}
|
|
||||||
allowEmpty
|
|
||||||
isSaving={isSaving}
|
|
||||||
onSave={onSave}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type CameraConfigEnableSwitchProps = {
|
type CameraConfigEnableSwitchProps = {
|
||||||
cameraName: string;
|
cameraName: string;
|
||||||
setRestartDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
setRestartDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user