mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-18 18:10:37 +08:00
When running under systemd (ASTRBOT_SYSTEMD=1), the click.confirm() prompt would raise Abort on user input, crashing the service. Skip the interactive confirmation and silently return instead.
80 lines
3.3 KiB
Python
80 lines
3.3 KiB
Python
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")
|
|
# Skip interactive prompt when running under systemd
|
|
if os.environ.get("ASTRBOT_SYSTEMD") == "1":
|
|
click.echo("Skipping interactive dashboard installation in systemd mode.")
|
|
return
|
|
if click.confirm(
|
|
"Install dashboard?",
|
|
default=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}")
|
|
else:
|
|
click.echo("Dashboard installation declined.")
|
|
|
|
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
|