mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: unify service configuration boundary
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from typing import Optional
|
||||
|
||||
from app.application.service import ServiceBaseHelper
|
||||
from app.schemas.system import NotificationConf
|
||||
from app.application.service import ServiceBaseHelper, get_service_configs
|
||||
from app.schemas.system import NotificationConf, NotificationSwitchConf
|
||||
from app.schemas.system import ServiceInfo
|
||||
from app.schemas.types import ModuleType, SystemConfigKey
|
||||
from app.schemas.types import MessageType, ModuleType, SystemConfigKey
|
||||
|
||||
|
||||
class NotificationHelper(ServiceBaseHelper[NotificationConf]):
|
||||
@@ -33,3 +33,23 @@ class NotificationHelper(ServiceBaseHelper[NotificationConf]):
|
||||
"""
|
||||
service = service or self.get_service(name=name)
|
||||
return bool(service and service.type == service_type)
|
||||
|
||||
|
||||
def get_notification_configs(
|
||||
include_disabled: bool = False,
|
||||
) -> list[NotificationConf]:
|
||||
"""返回通知配置列表,并按调用方需要决定是否包含禁用项。"""
|
||||
return list(
|
||||
NotificationHelper().get_configs(include_disabled=include_disabled).values()
|
||||
)
|
||||
|
||||
|
||||
def get_notification_switch(mtype: MessageType) -> Optional[str]:
|
||||
"""返回指定通知场景的目标范围。"""
|
||||
for switch in get_service_configs(
|
||||
SystemConfigKey.NotificationSwitchs,
|
||||
NotificationSwitchConf,
|
||||
):
|
||||
if switch.type == mtype.value:
|
||||
return switch.action
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user