mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-02-19 23:49:11 -05:00
modify notification module config
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import AnyHttpUrl
|
||||
@@ -27,7 +28,7 @@ class BasicConfig(BaseSettings):
|
||||
|
||||
|
||||
class AllEncompassingConfig(BaseSettings):
|
||||
model_config = SettingsConfigDict(toml_file="config.toml")
|
||||
model_config = SettingsConfigDict(toml_file=os.getenv("CONFIG_FILE", "./config.toml"))
|
||||
"""
|
||||
This class is used to load all configurations from the environment variables.
|
||||
It combines the BasicConfig with any additional configurations needed.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from media_manager.notification.service_providers.email import EmailNotificationsConfig
|
||||
from media_manager.notification.service_providers.gotify import GotifyConfig
|
||||
from media_manager.notification.service_providers.ntfy import NtfyConfig
|
||||
from media_manager.notification.service_providers.pushover import PushoverConfig
|
||||
|
||||
|
||||
class EmailConfig(BaseSettings):
|
||||
smtp_host: str = ""
|
||||
@@ -12,16 +17,10 @@ class EmailConfig(BaseSettings):
|
||||
|
||||
class NotificationConfig(BaseSettings):
|
||||
smtp_config: EmailConfig = EmailConfig()
|
||||
email: str | None = None # the email address to send notifications to
|
||||
email_notifications: EmailNotificationsConfig = EmailNotificationsConfig()
|
||||
gotify: GotifyConfig = GotifyConfig()
|
||||
ntfy: NtfyConfig = NtfyConfig()
|
||||
pushover: PushoverConfig = PushoverConfig()
|
||||
|
||||
ntfy_url: str | None = (
|
||||
None # e.g. https://ntfy.sh/your-topic (note lack of trailing slash)
|
||||
)
|
||||
|
||||
pushover_api_key: str | None = None
|
||||
pushover_user: str | None = None
|
||||
|
||||
gotify_api_key: str | None = None
|
||||
gotify_url: str | None = (
|
||||
None # e.g. https://gotify.example.com (note lack of trailing slash)
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
import media_manager.notification.utils
|
||||
from media_manager.notification.schemas import MessageNotification
|
||||
from media_manager.notification.service_providers.abstractNotificationServiceProvider import (
|
||||
@@ -5,10 +7,14 @@ from media_manager.notification.service_providers.abstractNotificationServicePro
|
||||
)
|
||||
from media_manager.config import AllEncompassingConfig
|
||||
|
||||
class EmailNotificationsConfig(BaseSettings):
|
||||
enabled: bool = False
|
||||
emails: list[str] = [] # the email addresses to send notifications to
|
||||
|
||||
|
||||
class EmailNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
def __init__(self):
|
||||
self.config = AllEncompassingConfig().notifications
|
||||
self.config = AllEncompassingConfig().notifications.email_notifications
|
||||
|
||||
def send_notification(self, message: MessageNotification) -> bool:
|
||||
subject = "MediaManager - " + message.title
|
||||
@@ -23,7 +29,10 @@ class EmailNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
media_manager.notification.utils.send_email(
|
||||
subject=subject, html=html, addressee=self.config.email
|
||||
)
|
||||
|
||||
for email in self.config.emails:
|
||||
media_manager.notification.utils.send_email(
|
||||
subject=subject, html=html, addressee=email
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import requests
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from media_manager.config import AllEncompassingConfig
|
||||
from media_manager.notification.schemas import MessageNotification
|
||||
from media_manager.notification.service_providers.abstractNotificationServiceProvider import (
|
||||
AbstractNotificationServiceProvider,
|
||||
)
|
||||
|
||||
class GotifyConfig(BaseSettings):
|
||||
enabled: bool = False
|
||||
api_key: str | None = None
|
||||
url: str | None = (
|
||||
None # e.g. https://gotify.example.com (note lack of trailing slash)
|
||||
)
|
||||
|
||||
class GotifyNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
"""
|
||||
@@ -12,11 +20,11 @@ class GotifyNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.config = AllEncompassingConfig().notifications
|
||||
self.config = AllEncompassingConfig().notifications.gotify
|
||||
|
||||
def send_notification(self, message: MessageNotification) -> bool:
|
||||
response = requests.post(
|
||||
url=f"{self.config.gotify_url}/message?token={self.config.gotify_api_key}",
|
||||
url=f"{self.config.url}/message?token={self.config.api_key}",
|
||||
json={
|
||||
"message": message.message,
|
||||
"title": message.title,
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import requests
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from media_manager.config import AllEncompassingConfig
|
||||
from media_manager.notification.schemas import MessageNotification
|
||||
from media_manager.notification.service_providers.abstractNotificationServiceProvider import (
|
||||
AbstractNotificationServiceProvider,
|
||||
)
|
||||
|
||||
class NtfyConfig(BaseSettings):
|
||||
enabled: bool = False
|
||||
url: str | None = (
|
||||
None # e.g. https://ntfy.sh/your-topic (note lack of trailing slash)
|
||||
)
|
||||
|
||||
class NtfyNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
"""
|
||||
@@ -12,11 +19,11 @@ class NtfyNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.config = AllEncompassingConfig().notifications
|
||||
self.config = AllEncompassingConfig().notifications.ntfy
|
||||
|
||||
def send_notification(self, message: MessageNotification) -> bool:
|
||||
response = requests.post(
|
||||
url=self.config.ntfy_url,
|
||||
url=self.config.url,
|
||||
data=message.message.encode(encoding="utf-8"),
|
||||
headers={
|
||||
"Title": "MediaManager - " + message.title,
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import requests
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
from media_manager.config import AllEncompassingConfig
|
||||
from media_manager.notification.schemas import MessageNotification
|
||||
from media_manager.notification.service_providers.abstractNotificationServiceProvider import (
|
||||
AbstractNotificationServiceProvider,
|
||||
)
|
||||
|
||||
class PushoverConfig(BaseSettings):
|
||||
enabled: bool = False
|
||||
api_key: str | None = None
|
||||
user: str | None = None
|
||||
|
||||
class PushoverNotificationServiceProvider(AbstractNotificationServiceProvider):
|
||||
def __init__(self):
|
||||
self.config = AllEncompassingConfig().notifications
|
||||
self.config = AllEncompassingConfig().notifications.pushover
|
||||
|
||||
def send_notification(self, message: MessageNotification) -> bool:
|
||||
response = requests.post(
|
||||
url="https://api.pushover.net/1/messages.json",
|
||||
params={
|
||||
"token": self.config.pushover_api_key,
|
||||
"user": self.config.pushover_user,
|
||||
"token": self.config.api_key,
|
||||
"user": self.config.user,
|
||||
"message": message.message,
|
||||
"title": "MediaManager - " + message.title,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user