diff --git a/astrbot/_internal/__init__.py b/astrbot/_internal/__init__.py index ccb201db8..7331d163d 100644 --- a/astrbot/_internal/__init__.py +++ b/astrbot/_internal/__init__.py @@ -1,4 +1,5 @@ """ Astbot内部实现 外部模块请勿导入 + """ diff --git a/astrbot/cli/commands/cmd_init.py b/astrbot/cli/commands/cmd_init.py index 7ffb5b6f5..f86596f78 100644 --- a/astrbot/cli/commands/cmd_init.py +++ b/astrbot/cli/commands/cmd_init.py @@ -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("你可以使用在线面版(需支持配置后端)来控制。") diff --git a/astrbot/cli/commands/cmd_run.py b/astrbot/cli/commands/cmd_run.py index 3e94e8fda..7122c0d4a 100644 --- a/astrbot/cli/commands/cmd_run.py +++ b/astrbot/cli/commands/cmd_run.py @@ -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) diff --git a/astrbot/cli/utils/__init__.py b/astrbot/cli/utils/__init__.py index e89d3bf29..7b8acbacf 100644 --- a/astrbot/cli/utils/__init__.py +++ b/astrbot/cli/utils/__init__.py @@ -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", ] diff --git a/astrbot/cli/utils/basic.py b/astrbot/cli/utils/basic.py deleted file mode 100644 index 1db033586..000000000 --- a/astrbot/cli/utils/basic.py +++ /dev/null @@ -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 diff --git a/astrbot/cli/utils/dashboard.py b/astrbot/cli/utils/dashboard.py new file mode 100644 index 000000000..83dbc0178 --- /dev/null +++ b/astrbot/cli/utils/dashboard.py @@ -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 diff --git a/astrbot/py.typed b/astrbot/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/dashboard/src/components/folder/BaseFolderItemSelector.vue b/dashboard/src/components/folder/BaseFolderItemSelector.vue index ca955ea3d..32c4a51e9 100644 --- a/dashboard/src/components/folder/BaseFolderItemSelector.vue +++ b/dashboard/src/components/folder/BaseFolderItemSelector.vue @@ -1,226 +1,57 @@ + - {{ labels.rootFolder || '根目录' }} + {{ labels.rootFolder || "根目录" }} - + -
+
- +
- +
+ + + {{ labels.rootFolder || "根目录" }} + + + {{ currentFolderLabel }} + +
+ + + + - +
- + {{ folder.name }} + - -
- mdi-folder-open-outline - mdi-folder-open-outline -

- {{ labels.emptyFolder || labels.noItems || '此文件夹为空' }} + {{ + labels.emptyFolder || labels.noItems || "此文件夹为空" + }}

@@ -451,21 +317,21 @@ prepend-icon="mdi-plus" @click="$emit('create')" > - {{ labels.createButton || '新建' }} + {{ labels.createButton || "新建" }} + - - {{ labels.cancelButton || '取消' }} + + + {{ labels.cancelButton || "取消" }} + - {{ labels.confirmButton || '确认' }} + {{ labels.confirmButton || "确认" }} @@ -474,427 +340,393 @@