refactor(module): simplify service instantiation with generics

This commit is contained in:
InfinityPacer
2024-09-27 04:04:56 +08:00
parent 5efcd6e6be
commit 2ce3ddb75a
19 changed files with 244 additions and 242 deletions

View File

@@ -4,24 +4,18 @@ from typing import Union, Tuple
from pywebpush import webpush, WebPushException
from app.core.config import global_vars, settings
from app.helper.notification import NotificationHelper
from app.log import logger
from app.modules import _ModuleBase, _MessageBase
from app.schemas import Notification
class WebPushModule(_ModuleBase, _MessageBase):
def init_module(self) -> None:
"""
初始化模块
"""
clients = NotificationHelper().get_clients()
if not clients:
return
self._configs = {}
for client in clients:
if client.type == "webpush" and client.enabled:
self._configs[client.name] = client
super().init_service(service_name=self.get_name().lower())
@staticmethod
def get_name() -> str: