diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index e369ad054..81d9b0bfe 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -1,5 +1,6 @@ import traceback import aiohttp +import os import ssl import certifi @@ -36,6 +37,7 @@ class PluginRoute(Route): "/plugin/off": ("POST", self.off_plugin), "/plugin/on": ("POST", self.on_plugin), "/plugin/reload": ("POST", self.reload_plugins), + "/plugin/readme": ("GET", self.get_plugin_readme), } self.core_lifecycle = core_lifecycle self.plugin_manager = plugin_manager @@ -317,3 +319,42 @@ class PluginRoute(Route): except Exception as e: logger.error(f"/api/plugin/on: {traceback.format_exc()}") return Response().error(str(e)).__dict__ + + async def get_plugin_readme(self): + plugin_name = request.args.get("name") + logger.debug(f"正在获取插件 {plugin_name} 的README文件内容") + + if not plugin_name: + logger.warning("插件名称为空") + return Response().error("插件名称不能为空").__dict__ + + plugin_obj = None + for plugin in self.plugin_manager.context.get_all_stars(): + if plugin.name == plugin_name: + plugin_obj = plugin + break + + if not plugin_obj: + logger.warning(f"插件 {plugin_name} 不存在") + return Response().error(f"插件 {plugin_name} 不存在").__dict__ + + plugin_dir = os.path.join(self.plugin_manager.plugin_store_path, plugin_obj.root_dir_name) + + if not os.path.isdir(plugin_dir): + logger.warning(f"无法找到插件目录: {plugin_dir}") + return Response().error(f"无法找到插件 {plugin_name} 的目录").__dict__ + + readme_path = os.path.join(plugin_dir, "README.md") + + if not os.path.isfile(readme_path): + logger.warning(f"插件 {plugin_name} 没有README文件") + return Response().error(f"插件 {plugin_name} 没有README文件").__dict__ + + try: + with open(readme_path, 'r', encoding='utf-8') as f: + readme_content = f.read() + + return Response().ok({"content": readme_content}, "成功获取README内容").__dict__ + except Exception as e: + logger.error(f"/api/plugin/readme: {traceback.format_exc()}") + return Response().error(f"读取README文件失败: {str(e)}").__dict__ diff --git a/dashboard/src/components/shared/ExtensionCard.vue b/dashboard/src/components/shared/ExtensionCard.vue index 18f845646..e6573260c 100644 --- a/dashboard/src/components/shared/ExtensionCard.vue +++ b/dashboard/src/components/shared/ExtensionCard.vue @@ -24,13 +24,10 @@ const emit = defineEmits([ 'install', 'uninstall', 'toggle-activation', - 'view-handlers' + 'view-handlers', + 'view-readme' ]); -const open = (link: string | undefined) => { - window.open(link, '_blank'); -}; - const reveal = ref(false); // 操作函数 @@ -70,6 +67,10 @@ const toggleActivation = () => { const viewHandlers = () => { emit('view-handlers', props.extension); }; + +const viewReadme = () => { + emit('view-readme', props.extension); +}; + \ No newline at end of file