From 6afac1f593230b690cf7463899568b5ba63094be Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Thu, 23 May 2024 16:25:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E9=81=A5=E6=B5=8B=E6=9C=8D=E5=8A=A1=E5=99=A8url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/audit/center/v2.py | 10 ++++------ pkg/config/migrations/m007_qcg_center_url.py | 20 ++++++++++++++++++++ pkg/core/stages/build_app.py | 1 + pkg/core/stages/migrate.py | 4 ++-- templates/system.json | 1 + 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 pkg/config/migrations/m007_qcg_center_url.py diff --git a/pkg/audit/center/v2.py b/pkg/audit/center/v2.py index 70d5138..234e6d2 100644 --- a/pkg/audit/center/v2.py +++ b/pkg/audit/center/v2.py @@ -9,8 +9,6 @@ from .groups import plugin from ...core import app -BACKEND_URL = "https://api.qchatgpt.rockchin.top/api/v2" - class V2CenterAPI: """中央服务器 v2 API 交互类""" @@ -23,7 +21,7 @@ class V2CenterAPI: plugin: plugin.V2PluginDataAPI = None """插件 API 组""" - def __init__(self, ap: app.Application, basic_info: dict = None, runtime_info: dict = None): + def __init__(self, ap: app.Application, backend_url: str, basic_info: dict = None, runtime_info: dict = None): """初始化""" logging.debug("basic_info: %s, runtime_info: %s", basic_info, runtime_info) @@ -31,7 +29,7 @@ class V2CenterAPI: apigroup.APIGroup._basic_info = basic_info apigroup.APIGroup._runtime_info = runtime_info - self.main = main.V2MainDataAPI(BACKEND_URL, ap) - self.usage = usage.V2UsageDataAPI(BACKEND_URL, ap) - self.plugin = plugin.V2PluginDataAPI(BACKEND_URL, ap) + self.main = main.V2MainDataAPI(backend_url, ap) + self.usage = usage.V2UsageDataAPI(backend_url, ap) + self.plugin = plugin.V2PluginDataAPI(backend_url, ap) diff --git a/pkg/config/migrations/m007_qcg_center_url.py b/pkg/config/migrations/m007_qcg_center_url.py new file mode 100644 index 0000000..cecd6b1 --- /dev/null +++ b/pkg/config/migrations/m007_qcg_center_url.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from .. import migration + + +@migration.migration_class("qcg-center-url-config", 7) +class QCGCenterURLConfigMigration(migration.Migration): + """迁移""" + + async def need_migrate(self) -> bool: + """判断当前环境是否需要运行此迁移""" + return "qcg-center-url" not in self.ap.system_cfg.data + + async def run(self): + """执行迁移""" + + if "qcg-center-url" not in self.ap.system_cfg.data: + self.ap.system_cfg.data["qcg-center-url"] = "https://api.qchatgpt.rockchin.top/api/v2" + + await self.ap.system_cfg.dump_config() diff --git a/pkg/core/stages/build_app.py b/pkg/core/stages/build_app.py index 39ecc02..fbdb5e8 100644 --- a/pkg/core/stages/build_app.py +++ b/pkg/core/stages/build_app.py @@ -34,6 +34,7 @@ class BuildAppStage(stage.BootingStage): center_v2_api = center_v2.V2CenterAPI( ap, + backend_url=ap.system_cfg.data["qcg-center-url"], basic_info={ "host_id": identifier.identifier["host_id"], "instance_id": identifier.identifier["instance_id"], diff --git a/pkg/core/stages/migrate.py b/pkg/core/stages/migrate.py index 4d5b8d8..69745fc 100644 --- a/pkg/core/stages/migrate.py +++ b/pkg/core/stages/migrate.py @@ -4,8 +4,8 @@ import importlib from .. import stage, app from ...config import migration -from ...config.migrations import m001_sensitive_word_migration, m002_openai_config_migration, m003_anthropic_requester_cfg_completion, m004_moonshot_cfg_completion, m006_vision_config -from ...config.migrations import m005_deepseek_cfg_completion +from ...config.migrations import m001_sensitive_word_migration, m002_openai_config_migration, m003_anthropic_requester_cfg_completion, m004_moonshot_cfg_completion +from ...config.migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_qcg_center_url @stage.stage_class("MigrationStage") diff --git a/templates/system.json b/templates/system.json index 72d29b9..0f6669f 100644 --- a/templates/system.json +++ b/templates/system.json @@ -10,5 +10,6 @@ "default": 1 }, "pipeline-concurrency": 20, + "qcg-center-url": "https://api.qchatgpt.rockchin.top/api/v2", "help-message": "QChatGPT - 😎高稳定性、🧩支持插件、🌏实时联网的 ChatGPT QQ 机器人🤖\n链接:https://q.rkcn.top" } \ No newline at end of file