diff --git a/backend/src/module/notification/plugin/bark.py b/backend/src/module/notification/plugin/bark.py index 0574db1e6..994f2aa0d 100644 --- a/backend/src/module/notification/plugin/bark.py +++ b/backend/src/module/notification/plugin/bark.py @@ -1,4 +1,5 @@ import logging +from typing import Optional from module.models import Notification from module.network import RequestContent @@ -7,10 +8,25 @@ class BarkNotification(RequestContent): - def __init__(self, token, **kwargs): + def __init__( + self, + token: str, + bark_params: Optional[dict], + bark_server: Optional[str], + **kwargs, + ) -> None: super().__init__() self.token = token - self.notification_url = "https://api.day.app/push" + self.params = bark_params + if bark_server is not None: + if not bark_server.startswith("http"): + bark_server = "https://" + bark_server + if not bark_server.endswith("push"): + bark_server = bark_server.rstrip("/") + "/push" + + self.notification_url = bark_server + else: + self.notification_url = "https://api.day.app/push" @staticmethod def gen_message(notify: Notification) -> str: @@ -21,7 +37,14 @@ def gen_message(notify: Notification) -> str: def post_msg(self, notify: Notification) -> bool: text = self.gen_message(notify) - data = {"title": notify.official_title, "body": text, "icon": notify.poster_path, "device_key": self.token} + data = { + "title": notify.official_title, + "body": text, + "icon": notify.poster_path, + "device_key": self.token, + } + if isinstance(self.params, dict): + data.update(self.params) resp = self.post_data(self.notification_url, data) logger.debug(f"Bark notification: {resp.status_code}") return resp.status_code == 200 diff --git a/webui/types/config.ts b/webui/types/config.ts index a53b1189a..6ad68559c 100644 --- a/webui/types/config.ts +++ b/webui/types/config.ts @@ -46,6 +46,8 @@ export interface Config { type: 'telegram' | 'server-chan' | 'bark' | 'wecom'; token: string; chat_id: string; + bark_params: string; + bark_server: string; }; experimental_openai: { enable: boolean;