From b6e054a73fdec30fcb109475920b7d1d19c9805d Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Tue, 11 Feb 2025 00:23:38 +0800 Subject: [PATCH] chore: migrations for `officialaccount` adapter --- .../m027_wx_official_account_config.py | 32 +++++++++++++ pkg/core/stages/migrate.py | 2 +- templates/platform.json | 4 +- templates/schema/platform.json | 45 +++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 pkg/core/migrations/m027_wx_official_account_config.py diff --git a/pkg/core/migrations/m027_wx_official_account_config.py b/pkg/core/migrations/m027_wx_official_account_config.py new file mode 100644 index 00000000..510b7108 --- /dev/null +++ b/pkg/core/migrations/m027_wx_official_account_config.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +from .. import migration + + +@migration.migration_class("wx-official-account-config", 27) +class WXOfficialAccountConfigMigration(migration.Migration): + """迁移""" + + async def need_migrate(self) -> bool: + """判断当前环境是否需要运行此迁移""" + + for adapter in self.ap.platform_cfg.data['platform-adapters']: + if adapter['adapter'] == 'officialaccount': + return False + + return True + + async def run(self): + """执行迁移""" + self.ap.platform_cfg.data['platform-adapters'].append({ + "adapter": "officialaccount", + "enable": False, + "token": "", + "EncodingAESKey": "", + "AppID": "", + "AppSecret": "", + "host": "0.0.0.0", + "port": 2287 + }) + + await self.ap.platform_cfg.dump_config() diff --git a/pkg/core/stages/migrate.py b/pkg/core/stages/migrate.py index 16faa53a..a1983f0b 100644 --- a/pkg/core/stages/migrate.py +++ b/pkg/core/stages/migrate.py @@ -9,7 +9,7 @@ from ..migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_ from ..migrations import m010_ollama_requester_config, m011_command_prefix_config, m012_runner_config, m013_http_api_config, m014_force_delay_config from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_api_timeout_params, m018_xai_config, m019_zhipuai_config from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config, m025_gewechat_config -from ..migrations import m026_qqofficial_config +from ..migrations import m026_qqofficial_config, m027_wx_official_account_config @stage.stage_class("MigrationStage") class MigrationStage(stage.BootingStage): diff --git a/templates/platform.json b/templates/platform.json index 5a1fca77..58742b37 100644 --- a/templates/platform.json +++ b/templates/platform.json @@ -68,11 +68,11 @@ }, { "adapter":"officialaccount", - "enable": true, + "enable": false, "token": "", "EncodingAESKey":"", - "AppSecret":"", "AppID":"", + "AppSecret":"", "host": "0.0.0.0", "port": 2287 } diff --git a/templates/schema/platform.json b/templates/schema/platform.json index f2db0f79..9a5deeb0 100644 --- a/templates/schema/platform.json +++ b/templates/schema/platform.json @@ -331,6 +331,51 @@ "description": "gewechat 的 token" } } + }, + { + "title": "微信公众号适配器", + "description": "用于接入微信公众号", + "properties": { + "adapter": { + "type": "string", + "const": "officialaccount" + }, + "enable": { + "type": "boolean", + "default": false, + "description": "是否启用此适配器" + }, + "token": { + "type": "string", + "default": "", + "description": "微信公众号的token" + }, + "EncodingAESKey": { + "type": "string", + "default": "", + "description": "微信公众号的EncodingAESKey" + }, + "AppID": { + "type": "string", + "default": "", + "description": "微信公众号的AppID" + }, + "AppSecret": { + "type": "string", + "default": "", + "description": "微信公众号的AppSecret" + }, + "host": { + "type": "string", + "default": "0.0.0.0", + "description": "监听的IP地址" + }, + "port": { + "type": "integer", + "default": 2287, + "description": "监听的端口" + } + } } ] }