S129 AstrBot热重载配置兼容
这个提交存在于:
父节点
102b749bb4
当前提交
f95f42c5bc
共有 1 个文件被更改,包括 19 次插入 和 2 次删除
21
main.py
21
main.py
|
|
@ -7,6 +7,7 @@ dispatch helpers for the runtime layer without starting a standalone server.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
import importlib
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -30,7 +31,17 @@ from adapters.webui_adapter import get_web_mount_manifest
|
||||||
from backend.route_registry import ROUTES
|
from backend.route_registry import ROUTES
|
||||||
from backend.services.ui_service import API_BASE
|
from backend.services.ui_service import API_BASE
|
||||||
from core.identity import RequestContext
|
from core.identity import RequestContext
|
||||||
from database.db_helper import Database, DatabaseSettings, load_database_settings, set_runtime_config_overrides
|
from database import db_helper as _database_db_helper
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not hasattr(_database_db_helper, "set_runtime_config_overrides"):
|
||||||
|
_database_db_helper = importlib.reload(_database_db_helper)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Database = _database_db_helper.Database
|
||||||
|
DatabaseSettings = _database_db_helper.DatabaseSettings
|
||||||
|
load_database_settings = _database_db_helper.load_database_settings
|
||||||
|
|
||||||
|
|
||||||
PLUGIN_NAME = "astrbot_plugin_imagestudio"
|
PLUGIN_NAME = "astrbot_plugin_imagestudio"
|
||||||
|
|
@ -86,7 +97,7 @@ def initialize_runtime_database(settings: DatabaseSettings | None = None) -> dic
|
||||||
def apply_astrbot_config_overrides(config: Any | None) -> dict[str, Any]:
|
def apply_astrbot_config_overrides(config: Any | None) -> dict[str, Any]:
|
||||||
mapping = _mapping_from_runtime_config(config)
|
mapping = _mapping_from_runtime_config(config)
|
||||||
patch = _runtime_config_patch_from_mapping(mapping)
|
patch = _runtime_config_patch_from_mapping(mapping)
|
||||||
set_runtime_config_overrides(patch)
|
_set_runtime_config_overrides(patch)
|
||||||
return {"applied": bool(patch), "keys": _flatten_config_keys(patch)}
|
return {"applied": bool(patch), "keys": _flatten_config_keys(patch)}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -270,6 +281,12 @@ def _mapping_from_runtime_config(config: Any | None) -> dict[str, Any]:
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
def _set_runtime_config_overrides(patch: Mapping[str, Any]) -> None:
|
||||||
|
setter = getattr(_database_db_helper, "set_runtime_config_overrides", None)
|
||||||
|
if callable(setter):
|
||||||
|
setter(patch)
|
||||||
|
|
||||||
|
|
||||||
def _runtime_config_argument(args: tuple[Any, ...], kwargs: Mapping[str, Any]) -> Any | None:
|
def _runtime_config_argument(args: tuple[Any, ...], kwargs: Mapping[str, Any]) -> Any | None:
|
||||||
if "config" in kwargs and kwargs["config"] is not None:
|
if "config" in kwargs and kwargs["config"] is not None:
|
||||||
return kwargs["config"]
|
return kwargs["config"]
|
||||||
|
|
|
||||||
正在加载…
添加表格
在新工单中引用