From b034cfb58d2ec69d676332edd022b96fdaa1f9c3 Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Thu, 4 Jul 2024 17:09:49 +0800 Subject: [PATCH 1/2] feat: Add optional parameters for BarkNotification constructor --- backend/src/module/notification/plugin/bark.py | 13 +++++++++++-- webui/types/config.ts | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/module/notification/plugin/bark.py b/backend/src/module/notification/plugin/bark.py index 0574db1e6..90c5417e5 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,9 +8,10 @@ class BarkNotification(RequestContent): - def __init__(self, token, **kwargs): + def __init__(self, token: str, bark_params: Optional[dict], **kwargs) -> None: super().__init__() self.token = token + self.params = bark_params self.notification_url = "https://api.day.app/push" @staticmethod @@ -21,7 +23,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..f01d55944 100644 --- a/webui/types/config.ts +++ b/webui/types/config.ts @@ -46,6 +46,7 @@ export interface Config { type: 'telegram' | 'server-chan' | 'bark' | 'wecom'; token: string; chat_id: string; + bark_params: string; }; experimental_openai: { enable: boolean; From 3742d447de3ab66ec1c03d8e473c2f994f7beffc Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Thu, 4 Jul 2024 17:19:11 +0800 Subject: [PATCH 2/2] feat: Add optional bark_server parameter to BarkNotification constructor --- backend/src/module/notification/plugin/bark.py | 18 ++++++++++++++++-- webui/types/config.ts | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/src/module/notification/plugin/bark.py b/backend/src/module/notification/plugin/bark.py index 90c5417e5..994f2aa0d 100644 --- a/backend/src/module/notification/plugin/bark.py +++ b/backend/src/module/notification/plugin/bark.py @@ -8,11 +8,25 @@ class BarkNotification(RequestContent): - def __init__(self, token: str, bark_params: Optional[dict], **kwargs) -> None: + def __init__( + self, + token: str, + bark_params: Optional[dict], + bark_server: Optional[str], + **kwargs, + ) -> None: super().__init__() self.token = token self.params = bark_params - self.notification_url = "https://api.day.app/push" + 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: diff --git a/webui/types/config.ts b/webui/types/config.ts index f01d55944..6ad68559c 100644 --- a/webui/types/config.ts +++ b/webui/types/config.ts @@ -47,6 +47,7 @@ export interface Config { token: string; chat_id: string; bark_params: string; + bark_server: string; }; experimental_openai: { enable: boolean;