mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-13 06:35:24 +03:00
Make notifications config only
This commit is contained in:
parent
6fbab846af
commit
242c254cce
@ -26,6 +26,9 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
||||
self.claim_headers = None
|
||||
self.web_pushers: list[WebPusher] = []
|
||||
|
||||
if not self.config.notifications.email:
|
||||
logger.warning("Email must be provided for push notifications to be sent.")
|
||||
|
||||
# Pull keys from PEM or generate if they do not exist
|
||||
self.vapid = Vapid01.from_file(os.path.join(CONFIG_DIR, "notifications.pem"))
|
||||
|
||||
@ -44,12 +47,15 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
||||
self.send_message(json.loads(payload))
|
||||
|
||||
def send_message(self, payload: dict[str, any]) -> None:
|
||||
if not self.config.notifications.email:
|
||||
return
|
||||
|
||||
# check for valid claim or create new one
|
||||
now = datetime.datetime.now().timestamp()
|
||||
if self.claim is None or self.claim["exp"] < now:
|
||||
# create new claim
|
||||
self.claim = {
|
||||
"sub": "mailto:test@example.com",
|
||||
"sub": f"mailto:{self.config.notifications.email}",
|
||||
"aud": "https://fcm.googleapis.com",
|
||||
"exp": (
|
||||
datetime.datetime.now() + datetime.timedelta(hours=1)
|
||||
|
||||
@ -171,8 +171,8 @@ class AuthConfig(FrigateBaseModel):
|
||||
|
||||
class NotificationConfig(FrigateBaseModel):
|
||||
enabled: bool = Field(default=False, title="Enable notifications")
|
||||
base_url: Optional[str] = Field(
|
||||
default=None, title="Base url for notification link and image."
|
||||
email: Optional[str] = Field(
|
||||
default=None, title="Email required for push."
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -60,13 +60,17 @@ export default function Settings() {
|
||||
const settingsViews = useMemo(() => {
|
||||
const views = [...allSettingsViews];
|
||||
|
||||
if (!("Notification" in window) || !window.isSecureContext) {
|
||||
if (
|
||||
!("Notification" in window) ||
|
||||
!window.isSecureContext ||
|
||||
!config?.notifications.enabled
|
||||
) {
|
||||
const index = views.indexOf("notifications");
|
||||
views.splice(index, 1);
|
||||
}
|
||||
|
||||
return views;
|
||||
}, []);
|
||||
}, [config]);
|
||||
|
||||
// TODO: confirm leave page
|
||||
const [unsavedChanges, setUnsavedChanges] = useState(false);
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Heading from "@/components/ui/heading";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { FrigateConfig } from "@/types/frigateConfig";
|
||||
import axios from "axios";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
@ -69,27 +67,6 @@ export default function NotificationView() {
|
||||
Notification Settings
|
||||
</Heading>
|
||||
|
||||
<div className="mt-2 space-y-6">
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-row items-center justify-start gap-2">
|
||||
<Switch
|
||||
id="auto-live"
|
||||
checked={config?.notifications?.enabled}
|
||||
onCheckedChange={() => {}}
|
||||
/>
|
||||
<Label className="cursor-pointer" htmlFor="auto-live">
|
||||
Notifications
|
||||
</Label>
|
||||
</div>
|
||||
<div className="my-2 text-sm text-muted-foreground">
|
||||
<p>
|
||||
Enable notifications for Frigate alerts. This requires Frigate
|
||||
to be externally accessible.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{config?.notifications.enabled && (
|
||||
<div className="mt-2 space-y-6">
|
||||
<div className="space-y-3">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user