修复:启动链,参数/环境变量加载逻辑优化

This commit is contained in:
LIghtJUNction
2026-03-20 19:44:12 +08:00
parent 4f04d39348
commit 78edc0fff8
8 changed files with 476 additions and 645 deletions

View File

@@ -1,4 +1,5 @@
"""
Astbot内部实现
外部模块请勿导入
"""

View File

@@ -7,7 +7,7 @@ from pathlib import Path
import click
from filelock import FileLock, Timeout
from astrbot.cli.utils import check_dashboard
from astrbot.cli.utils import DashboardManager
from astrbot.core.config.default import DEFAULT_CONFIG
from astrbot.core.utils.astrbot_path import astrbot_paths
@@ -146,7 +146,7 @@ async def initialize_astrbot(
if os.environ.get("ASTRBOT_SYSTEMD") == "1":
click.echo("Systemd detected: Skipping dashboard check.")
else:
await check_dashboard(astrbot_root)
await DashboardManager().ensure_installed(astrbot_root)
else:
click.echo("你可以使用在线面版(需支持配置后端)来控制。")

View File

@@ -53,7 +53,7 @@ import click
from dotenv import load_dotenv
from filelock import FileLock, Timeout
from astrbot.cli.utils import check_dashboard
from astrbot.cli.utils import DashboardManager
from astrbot.runtime_bootstrap import initialize_runtime_bootstrap
initialize_runtime_bootstrap()
@@ -95,7 +95,7 @@ async def run_astrbot(astrbot_root: Path) -> None:
):
# Avoid blocking when running under systemd by waiting for input
if os.environ.get("ASTRBOT_SYSTEMD") != "1":
await check_dashboard(astrbot_root)
await DashboardManager().ensure_installed(astrbot_root)
log_broker = LogBroker()
LogManager.set_queue_handler(logger, log_broker)

View File

@@ -1,14 +1,12 @@
from .basic import (
check_dashboard,
)
from .dashboard import DashboardManager
from .plugin import PluginStatus, build_plug_list, get_git_repo, manage_plugin
from .version_comparator import VersionComparator
__all__ = [
"DashboardManager",
"PluginStatus",
"VersionComparator",
"build_plug_list",
"check_dashboard",
"get_git_repo",
"manage_plugin",
]

View File

@@ -1,71 +0,0 @@
from importlib import resources
from pathlib import Path
import click
_BUNDLED_DIST = resources.files("astrbot") / "dashboard" / "dist"
async def check_dashboard(astrbot_root: Path) -> None:
"""Check if the dashboard is installed"""
from astrbot.core.config.default import VERSION
from astrbot.core.utils.io import download_dashboard, get_dashboard_version
from .version_comparator import VersionComparator
# If the wheel ships bundled dashboard assets, no network download is needed.
if _BUNDLED_DIST.is_dir():
click.echo("Dashboard is bundled with the package skipping download.")
return
try:
dashboard_version = await get_dashboard_version()
match dashboard_version:
case None:
click.echo("Dashboard is not installed")
if click.confirm(
"Install dashboard?",
default=True,
abort=True,
):
click.echo("Installing dashboard...")
try:
await download_dashboard(
path="data/dashboard.zip",
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
click.echo("Dashboard installed successfully")
except Exception as e:
click.echo(f"Failed to install dashboard: {e}")
case str():
if VersionComparator.compare_version(VERSION, dashboard_version) <= 0:
click.echo("Dashboard is already up to date")
return
try:
version = dashboard_version.split("v")[1]
click.echo(f"Dashboard version: {version}")
await download_dashboard(
path="data/dashboard.zip",
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
except Exception as e:
click.echo(f"Failed to download dashboard: {e}")
return
except FileNotFoundError:
click.echo("Initializing dashboard directory...")
try:
await download_dashboard(
path=str(astrbot_root / "data" / "dashboard.zip"),
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
click.echo("Dashboard initialized successfully")
except Exception as e:
click.echo(f"Failed to download dashboard: {e}")
return

View File

@@ -0,0 +1,71 @@
from importlib import resources
from pathlib import Path
import click
from .version_comparator import VersionComparator
class DashboardManager:
_bundled_dist = resources.files("astrbot") / "dashboard" / "dist"
async def ensure_installed(self, astrbot_root: Path) -> None:
"""Ensure the dashboard assets are installed and up to date."""
from astrbot.core.config.default import VERSION
from astrbot.core.utils.io import download_dashboard, get_dashboard_version
if self._bundled_dist.is_dir():
click.echo("Dashboard is bundled with the package skipping download.")
return
try:
dashboard_version = await get_dashboard_version()
match dashboard_version:
case None:
click.echo("Dashboard is not installed")
if click.confirm(
"Install dashboard?",
default=True,
abort=True,
):
click.echo("Installing dashboard...")
try:
await download_dashboard(
path="data/dashboard.zip",
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
click.echo("Dashboard installed successfully")
except Exception as e:
click.echo(f"Failed to install dashboard: {e}")
case str():
if VersionComparator.compare_version(VERSION, dashboard_version) <= 0:
click.echo("Dashboard is already up to date")
return
try:
version = dashboard_version.split("v")[1]
click.echo(f"Dashboard version: {version}")
await download_dashboard(
path="data/dashboard.zip",
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
except Exception as e:
click.echo(f"Failed to download dashboard: {e}")
return
except FileNotFoundError:
click.echo("Initializing dashboard directory...")
try:
await download_dashboard(
path=str(astrbot_root / "data" / "dashboard.zip"),
extract_path=str(astrbot_root / "data"),
version=f"v{VERSION}",
latest=False,
)
click.echo("Dashboard initialized successfully")
except Exception as e:
click.echo(f"Failed to download dashboard: {e}")
return

0
astrbot/py.typed Normal file
View File

File diff suppressed because it is too large Load Diff