mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-27 17:17:40 +03:00
notification fixes
the pubkey was not being returned if notifications was not enabled at the global level
This commit is contained in:
parent
472a1d7954
commit
eb3d0ddfb6
@ -21,7 +21,12 @@ router = APIRouter(tags=[Tags.notifications])
|
|||||||
|
|
||||||
@router.get("/notifications/pubkey")
|
@router.get("/notifications/pubkey")
|
||||||
def get_vapid_pub_key(request: Request):
|
def get_vapid_pub_key(request: Request):
|
||||||
if not request.app.frigate_config.notifications.enabled:
|
config = request.app.frigate_config
|
||||||
|
notifications_enabled = config.notifications.enabled
|
||||||
|
camera_notifications_enabled = [
|
||||||
|
c for c in config.cameras.values() if c.enabled and c.notifications.enabled
|
||||||
|
]
|
||||||
|
if not (notifications_enabled or camera_notifications_enabled):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content=({"success": False, "message": "Notifications are not enabled."}),
|
content=({"success": False, "message": "Notifications are not enabled."}),
|
||||||
status_code=400,
|
status_code=400,
|
||||||
|
|||||||
@ -118,50 +118,6 @@ export default function NotificationView({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [changedValue]);
|
}, [changedValue]);
|
||||||
|
|
||||||
// notification key handling
|
|
||||||
|
|
||||||
const { data: publicKey } = useSWR(
|
|
||||||
config?.notifications?.enabled ? "notifications/pubkey" : null,
|
|
||||||
{ revalidateOnFocus: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
const subscribeToNotifications = useCallback(
|
|
||||||
(registration: ServiceWorkerRegistration) => {
|
|
||||||
if (registration) {
|
|
||||||
addMessage(
|
|
||||||
"notification_settings",
|
|
||||||
t("notification.unsavedRegistrations"),
|
|
||||||
undefined,
|
|
||||||
"registration",
|
|
||||||
);
|
|
||||||
|
|
||||||
registration.pushManager
|
|
||||||
.subscribe({
|
|
||||||
userVisibleOnly: true,
|
|
||||||
applicationServerKey: publicKey,
|
|
||||||
})
|
|
||||||
.then((pushSubscription) => {
|
|
||||||
axios
|
|
||||||
.post("notifications/register", {
|
|
||||||
sub: pushSubscription,
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
toast.error(t("notification.toast.error.registerFailed"), {
|
|
||||||
position: "top-center",
|
|
||||||
});
|
|
||||||
pushSubscription.unsubscribe();
|
|
||||||
registration.unregister();
|
|
||||||
setRegistration(null);
|
|
||||||
});
|
|
||||||
toast.success(t("notification.toast.success.registered"), {
|
|
||||||
position: "top-center",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[publicKey, addMessage, t],
|
|
||||||
);
|
|
||||||
|
|
||||||
// notification state
|
// notification state
|
||||||
|
|
||||||
const [registration, setRegistration] =
|
const [registration, setRegistration] =
|
||||||
@ -206,7 +162,55 @@ export default function NotificationView({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const watchCameras = form.watch("cameras");
|
const watchAllEnabled = form.watch("allEnabled");
|
||||||
|
const watchCameras = useMemo(() => form.watch("cameras") || [], [form]);
|
||||||
|
|
||||||
|
const { data: publicKey } = useSWR(
|
||||||
|
config &&
|
||||||
|
(config.notifications?.enabled ||
|
||||||
|
watchAllEnabled ||
|
||||||
|
(Array.isArray(watchCameras) && watchCameras.length > 0))
|
||||||
|
? "notifications/pubkey"
|
||||||
|
: null,
|
||||||
|
{ revalidateOnFocus: false },
|
||||||
|
);
|
||||||
|
|
||||||
|
const subscribeToNotifications = useCallback(
|
||||||
|
(registration: ServiceWorkerRegistration) => {
|
||||||
|
if (registration) {
|
||||||
|
addMessage(
|
||||||
|
"notification_settings",
|
||||||
|
t("notification.unsavedRegistrations"),
|
||||||
|
undefined,
|
||||||
|
"registration",
|
||||||
|
);
|
||||||
|
|
||||||
|
registration.pushManager
|
||||||
|
.subscribe({
|
||||||
|
userVisibleOnly: true,
|
||||||
|
applicationServerKey: publicKey,
|
||||||
|
})
|
||||||
|
.then((pushSubscription) => {
|
||||||
|
axios
|
||||||
|
.post("notifications/register", {
|
||||||
|
sub: pushSubscription,
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
toast.error(t("notification.toast.error.registerFailed"), {
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
pushSubscription.unsubscribe();
|
||||||
|
registration.unregister();
|
||||||
|
setRegistration(null);
|
||||||
|
});
|
||||||
|
toast.success(t("notification.toast.success.registered"), {
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[publicKey, addMessage, t],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (watchCameras.length > 0) {
|
if (watchCameras.length > 0) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user