2025-09-12 06:19:29 -05:00
|
|
|
import { useContext } from "react";
|
|
|
|
|
import { AuthContext } from "@/context/auth-context";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2026-03-04 10:07:34 -06:00
|
|
|
import { isReplayCamera } from "@/utils/cameraUtil";
|
2025-09-12 06:19:29 -05:00
|
|
|
|
|
|
|
|
export function useAllowedCameras() {
|
|
|
|
|
const { auth } = useContext(AuthContext);
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config", {
|
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
auth.user?.role === "viewer" ||
|
|
|
|
|
auth.user?.role === "admin" ||
|
2026-01-28 06:27:46 -08:00
|
|
|
!auth.isAuthenticated // anonymous internal port
|
2025-09-12 06:19:29 -05:00
|
|
|
) {
|
2026-03-04 10:07:34 -06:00
|
|
|
// return all cameras, excluding replay cameras
|
|
|
|
|
return config?.cameras
|
|
|
|
|
? Object.keys(config.cameras).filter((name) => !isReplayCamera(name))
|
|
|
|
|
: [];
|
2025-09-12 06:19:29 -05:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 10:07:34 -06:00
|
|
|
return (auth.allowedCameras || []).filter((name) => !isReplayCamera(name));
|
2025-09-12 06:19:29 -05:00
|
|
|
}
|