From 8c976303a436977e4fa55798ea169536893418e0 Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Tue, 15 Oct 2024 21:42:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20system.json=20=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E8=A7=86=E5=8C=96=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/api/http/controller/groups/settings.py | 6 +- pkg/core/stages/load_config.py | 3 +- pkg/utils/schema.py | 1 + templates/schema/pipeline.json | 134 ++++++++++++++++ templates/schema/system.json | 176 ++++++++++++--------- web/src/pages/Settings.vue | 89 +++++++++-- 6 files changed, 323 insertions(+), 86 deletions(-) create mode 100644 templates/schema/pipeline.json diff --git a/pkg/api/http/controller/groups/settings.py b/pkg/api/http/controller/groups/settings.py index 72f41d97..b08fb525 100644 --- a/pkg/api/http/controller/groups/settings.py +++ b/pkg/api/http/controller/groups/settings.py @@ -44,7 +44,11 @@ class SettingsRouterGroup(group.RouterGroup): async def _(manager_name: str) -> str: data = await quart.request.json manager = self.ap.settings_mgr.get_manager(manager_name) - manager.data = data['data'] + # manager.data = data['data'] + for k, v in data['data'].items(): + manager.data[k] = v + + await manager.dump_config() return self.success(data={ "data": manager.data }) diff --git a/pkg/core/stages/load_config.py b/pkg/core/stages/load_config.py index b9d1d4db..f25bc4a5 100644 --- a/pkg/core/stages/load_config.py +++ b/pkg/core/stages/load_config.py @@ -33,7 +33,8 @@ class LoadConfigStage(stage.BootingStage): ap.settings_mgr.register_manager( name="pipeline.json", description="消息处理流水线配置", - manager=ap.pipeline_cfg + manager=ap.pipeline_cfg, + schema=schema.CONFIG_PIPELINE_SCHEMA ) ap.settings_mgr.register_manager( diff --git a/pkg/utils/schema.py b/pkg/utils/schema.py index 8dca2c83..3ca51045 100644 --- a/pkg/utils/schema.py +++ b/pkg/utils/schema.py @@ -8,3 +8,4 @@ def load_schema(schema_path: str) -> dict: CONFIG_SYSTEM_SCHEMA = load_schema("templates/schema/system.json") +CONFIG_PIPELINE_SCHEMA = load_schema("templates/schema/pipeline.json") \ No newline at end of file diff --git a/templates/schema/pipeline.json b/templates/schema/pipeline.json new file mode 100644 index 00000000..aae2eb42 --- /dev/null +++ b/templates/schema/pipeline.json @@ -0,0 +1,134 @@ +{ + "type": "object", + "layout": "expansion-panels", + "properties": { + "access-control": { + "type": "object", + "title": "访问控制", + "properties": { + "mode": { + "type": "string", + "title": "访问控制模式", + "description": "访问控制模式,支持黑名单和白名单", + "enum": ["blacklist", "whitelist"] + }, + "blacklist": { + "type": "array", + "title": "黑名单", + "description": "黑名单中的会话将无法使用机器人,仅在访问控制模式为黑名单时有效", + "items": { + "type": "string", + "format": "regex", + "pattern": "^(person|group)_(\\d)*$" + } + }, + "whitelist": { + "type": "array", + "title": "白名单", + "description": "仅白名单中的会话可以使用机器人,仅在访问控制模式为白名单时有效", + "items": { + "type": "string", + "format": "regex", + "pattern": "^(person|group)_(\\d)*$" + } + } + }, + "required": ["mode"] + }, + "respond-rules": { + "type": "object", + "title": "群内响应规则", + "properties": { + "default": { + "type": "object", + "title": "默认响应规则", + "properties": { + "at": { + "type": "boolean", + "title": "是否响应 @ 消息", + "layout": { + "comp": "switch", + "props": { + "color": "primary" + } + } + }, + "prefix": { + "type": "array", + "title": "前缀响应", + "items": { + "type": "string" + } + }, + "regexp": { + "type": "array", + "title": "正则表达式响应", + "items": { + "type": "string", + "format": "regex" + } + }, + "random": { + "type": "number", + "title": "随机响应概率", + "minimum": 0, + "maximum": 1, + "step": 0.01, + "layout": { + "comp": "slider", + "props": { + "color": "primary" + } + } + } + } + } + }, + "patternProperties": { + "^(person|group).*$": { + "type": "object", + "properties": { + "at": { + "type": "boolean", + "title": "是否响应 @ 消息", + "layout": { + "comp": "switch", + "props": { + "color": "primary" + } + } + }, + "prefix": { + "type": "array", + "title": "前缀响应", + "items": { + "type": "string" + } + }, + "regexp": { + "type": "array", + "title": "正则表达式响应", + "items": { + "type": "string", + "format": "regex" + } + }, + "random": { + "type": "number", + "title": "随机响应概率", + "minimum": 0, + "maximum": 1, + "step": 0.01, + "layout": { + "comp": "slider", + "props": { + "color": "primary" + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/templates/schema/system.json b/templates/schema/system.json index 8114d198..e6268a70 100644 --- a/templates/schema/system.json +++ b/templates/schema/system.json @@ -1,80 +1,112 @@ { "type": "object", + "layout": "expansion-panels", "properties": { - "admin-sessions": { - "type": "array", - "items": { - "type": "string" - } - }, - "network-proxies": { - "type": "object", - "properties": { - "http": { - "type": "string" - }, - "https": { - "type": "string" - } - } - }, - "report-usage": { - "type": "boolean" - }, - "logging-level": { + "admin-sessions": { + "type": "array", + "title": "管理员会话", + "description": "", + "items": { + "type": "string", + "format": "regex", + "pattern": "^(person|group)_(\\d)*$" + } + }, + "network-proxies": { + "type": "object", + "title": "网络代理", + "properties": { + "http": { "type": "string" - }, - "session-concurrency": { - "type": "object", - "properties": { - "default": { - "type": "integer" - } - }, - "patternProperties": { - "^(person|group).*$": { - "type": "integer" - } - } - }, - "pipeline-concurrency": { - "type": "integer" - }, - "qcg-center-url": { + }, + "https": { "type": "string" - }, - "help-message": { - "type": "string" - }, - "http-api": { - "type": "object", - "properties": { - "enable": { - "type": "boolean" - }, - "host": { - "type": "string" - }, - "port": { - "type": "integer" - } - } - }, - "persistence": { - "type": "object", - "properties": { - "sqlite": { - "type": "object", - "properties": { - "path": { - "type": "string" - } - } - }, - "use": { - "type": "string" - } + } + } + }, + "report-usage": { + "type": "boolean", + "title": "是否上报遥测数据", + "layout": { + "comp": "switch", + "props": { + "color": "primary" } } + }, + "logging-level": { + "type": "string", + "title": "日志等级" + }, + "session-concurrency": { + "type": "object", + "title": "会话并行消息数", + "properties": { + "default": { + "type": "integer", + "title": "会话默认并行消息数" + } + }, + "patternProperties": { + "^(person|group).*$": { + "type": "integer" + } + } + }, + "pipeline-concurrency": { + "type": "integer", + "title": "全局并行消息数" + }, + "qcg-center-url": { + "type": "string", + "title": "遥测服务器地址" + }, + "help-message": { + "type": "string", + "title": "help 命令消息", + "layout": "textarea" + }, + "http-api": { + "type": "object", + "title": "HTTP 接口", + "properties": { + "enable": { + "type": "boolean", + "layout": { + "comp": "switch", + "props": { + "color": "primary" + } + }, + "title": "是否启用" + }, + "host": { + "type": "string" + }, + "port": { + "type": "integer" + } + } + }, + "persistence": { + "type": "object", + "title": "持久化设置", + "properties": { + "sqlite": { + "type": "object", + "title": "sqlite", + "properties": { + "path": { + "type": "string" + } + } + }, + "use": { + "type": "string", + "title": "所使用的数据库", + "enum": ["sqlite"] + } + } + } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/web/src/pages/Settings.vue b/web/src/pages/Settings.vue index c6bb6d71..ee240fb6 100644 --- a/web/src/pages/Settings.vue +++ b/web/src/pages/Settings.vue @@ -18,12 +18,12 @@