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