ForcePilot/backend/package/yuxi/channel/application/service/config_service.py
Kris 9a8a27bf36 feat(channel): 新增渠道网关模块完整实现
本次提交新增了完整的多渠道消息网关系统,包括:
1. 支持飞书、钉钉、Web、Hook 四种渠道的适配器与配置
2. 领域模型层:消息、会话、绑定、出箱等核心实体
3. 应用服务层:管道、中间件、DTO 与业务逻辑
4. 基础设施层:持久化、过滤器、队列等端口实现
5. 接口层:REST API、SSE、WebSocket 通信端点
6. 前端页面与路由配置,添加渠道管理菜单
7. 新增相关依赖包与 docker-compose 部署配置
2026-05-30 21:53:09 +08:00

58 lines
1.7 KiB
Python

from __future__ import annotations
import hashlib
import json
from yuxi.channel.domain.middleware.configurable import Configurable
from yuxi.channel.domain.port.config_reload_port import ConfigReloadPort
from yuxi.channel.domain.service.pipeline import Pipeline
from yuxi.channel.infrastructure.config.channel_config import ChannelConfig
class ConfigService:
def __init__(
self,
config_data: dict,
config_reload: ConfigReloadPort,
pipeline: Pipeline,
*,
channel_config: ChannelConfig | None = None,
) -> None:
self._config = config_data
self._config_reload = config_reload
self._pipeline = pipeline
self._channel_config = channel_config
async def reload(self) -> tuple[list[str], str | None]:
reloaded = await self._config_reload.reload()
if reloaded:
self._config = reloaded
updated = self._update_configurable_middlewares()
if self._channel_config:
items = await self._channel_config.on_config_updated(self._config)
if items:
updated.extend(items)
config_hash = hashlib.sha256(
json.dumps(self._config, sort_keys=True).encode(),
).hexdigest()[:8]
return updated, config_hash
@property
def config(self) -> dict:
return self._config
def _update_configurable_middlewares(self) -> list[str]:
updated: list[str] = []
for mw in self._pipeline.middlewares:
if isinstance(mw, Configurable):
items = mw.on_config_updated(self._config)
if items:
updated.extend(items)
return updated