Resolve and repair dashboard static files for startup. Args: webui_dir: Optional explicit WebUI directory path from CLI. Returns: The directory path to serve, or None when no usable WebUI can be prepared.
(webui_dir: str | None = None)
| 95 | |
| 96 | |
| 97 | async def check_dashboard_files(webui_dir: str | None = None): |
| 98 | """Resolve and repair dashboard static files for startup. |
| 99 | |
| 100 | Args: |
| 101 | webui_dir: Optional explicit WebUI directory path from CLI. |
| 102 | |
| 103 | Returns: |
| 104 | The directory path to serve, or None when no usable WebUI can be prepared. |
| 105 | """ |
| 106 | |
| 107 | # 指定webui目录 |
| 108 | if webui_dir: |
| 109 | if os.path.exists(webui_dir): |
| 110 | logger.info("Using WebUI directory: %s", webui_dir) |
| 111 | return webui_dir |
| 112 | logger.warning("WebUI directory not found: %s. Using default.", webui_dir) |
| 113 | |
| 114 | data_dist_path = Path(get_astrbot_data_path()) / "dist" |
| 115 | bundled_dist = get_bundled_dashboard_dist_path() |
| 116 | if data_dist_path.exists(): |
| 117 | v = get_dashboard_dist_version(data_dist_path) |
| 118 | if is_dashboard_dist_compatible(data_dist_path, VERSION): |
| 119 | logger.info("WebUI is up to date.") |
| 120 | return str(data_dist_path) |
| 121 | |
| 122 | if should_use_bundled_dashboard_dist(data_dist_path, VERSION): |
| 123 | logger.info( |
| 124 | "Replacing data/dist with bundled WebUI because its version does not match core version v%s.", |
| 125 | VERSION, |
| 126 | ) |
| 127 | try: |
| 128 | remove_dir(str(data_dist_path)) |
| 129 | shutil.copytree(bundled_dist, data_dist_path) |
| 130 | return str(data_dist_path) |
| 131 | except Exception as e: |
| 132 | logger.warning( |
| 133 | "Failed to replace data/dist with bundled WebUI: %s. Using bundled WebUI directly.", |
| 134 | e, |
| 135 | ) |
| 136 | return str(bundled_dist) |
| 137 | |
| 138 | if is_dashboard_version_compatible(v, VERSION): |
| 139 | logger.warning( |
| 140 | "WebUI files are incomplete for v%s. Re-downloading WebUI.", |
| 141 | VERSION, |
| 142 | ) |
| 143 | elif v is not None: |
| 144 | logger.warning( |
| 145 | "WebUI version mismatch: %s, expected v%s. Re-downloading WebUI.", |
| 146 | v, |
| 147 | VERSION, |
| 148 | ) |
| 149 | else: |
| 150 | logger.warning( |
| 151 | "WebUI version file is missing. Re-downloading WebUI v%s.", |
| 152 | VERSION, |
| 153 | ) |
| 154 |