fix 插件代码判定

This commit is contained in:
jxxghp
2025-05-08 14:26:47 +08:00
parent 1883607118
commit 645de137f2
2 changed files with 20 additions and 9 deletions
+9 -5
View File
@@ -465,13 +465,15 @@ class PluginManager(metaclass=Singleton):
}] }]
""" """
ret_apis = [] ret_apis = []
for plugin_id, plugin in self._running_plugins.items(): if pid:
plugins = {pid: self._running_plugins.get(pid)}
else:
plugins = self._running_plugins
for plugin_id, plugin in plugins.items():
if pid and pid != plugin_id: if pid and pid != plugin_id:
continue continue
if hasattr(plugin, "get_api") and ObjectUtils.check_method(plugin.get_api): if hasattr(plugin, "get_api") and ObjectUtils.check_method(plugin.get_api):
try: try:
if not plugin.get_state():
continue
apis = plugin.get_api() or [] apis = plugin.get_api() or []
for api in apis: for api in apis:
api["path"] = f"/{plugin_id}{api['path']}" api["path"] = f"/{plugin_id}{api['path']}"
@@ -831,7 +833,8 @@ class PluginManager(metaclass=Singleton):
logger.debug(f"获取插件是否在本地包中存在失败,{e}") logger.debug(f"获取插件是否在本地包中存在失败,{e}")
return False return False
def get_plugins_from_market(self, market: str, package_version: Optional[str] = None) -> Optional[List[schemas.Plugin]]: def get_plugins_from_market(self, market: str, package_version: Optional[str] = None) -> Optional[
List[schemas.Plugin]]:
""" """
从指定的市场获取插件信息 从指定的市场获取插件信息
:param market: 市场的 URL 或标识 :param market: 市场的 URL 或标识
@@ -845,7 +848,8 @@ class PluginManager(metaclass=Singleton):
# 获取在线插件 # 获取在线插件
online_plugins = self.pluginhelper.get_plugins(market, package_version) online_plugins = self.pluginhelper.get_plugins(market, package_version)
if online_plugins is None: if online_plugins is None:
logger.warning(f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接") logger.warning(
f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接")
return [] return []
ret_plugins = [] ret_plugins = []
add_time = len(online_plugins) add_time = len(online_plugins)
+11 -4
View File
@@ -52,21 +52,28 @@ class ObjectUtils:
# 跳过空行 # 跳过空行
if not line: if not line:
continue continue
# 处理行注释 # 处理"""单行注释
if line.startswith(('"""', "'''")) and line.endswith(('"""', "'''")):
continue
# 处理"""多行注释
if line.startswith(('"""', "'''")): if line.startswith(('"""', "'''")):
in_comment = not in_comment in_comment = not in_comment
continue continue
# 在注释中则跳过 # 在注释中则跳过
if in_comment: if in_comment:
continue continue
# 跳过注释、pass语句、装饰器、函数定义行 # 跳过#注释、pass语句、装饰器、函数定义行
if line.startswith('#') or line == "pass" or line.startswith('@') or line.startswith('def '): if (line.startswith('#')
or line == "pass"
or line.startswith('@')
or line.startswith('def ')):
continue continue
# 发现有效代码行 # 发现有效代码行
return True return True
# 没有有效代码行 # 没有有效代码行
return False return False
except Exception: except Exception as err:
print(err)
# 源代码分析失败时,进行字节码分析 # 源代码分析失败时,进行字节码分析
code_obj = func.__code__ code_obj = func.__code__
instructions = list(dis.get_instructions(code_obj)) instructions = list(dis.get_instructions(code_obj))