feat: support multiple images and improve error logging for plugin updates
This commit is contained in:
@@ -263,7 +263,13 @@ class OpenWebUICommunityClient:
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f" [DEBUG] Update failed status: {response.status_code}")
|
||||
print(f" [DEBUG] Update failed response: {response.text[:500]}")
|
||||
try:
|
||||
error_detail = response.json()
|
||||
print(
|
||||
f" [DEBUG] Update failed error detail: {json.dumps(error_detail, indent=2)}"
|
||||
)
|
||||
except Exception:
|
||||
print(f" [DEBUG] Update failed response text: {response.text[:1000]}")
|
||||
|
||||
response.raise_for_status()
|
||||
return True
|
||||
@@ -467,14 +473,15 @@ class OpenWebUICommunityClient:
|
||||
readme_content = self._find_readme(file_path)
|
||||
|
||||
# 查找并上传图片
|
||||
media_urls = None
|
||||
image_path = self._find_image(file_path)
|
||||
if image_path:
|
||||
media_urls = []
|
||||
image_paths = self._find_images(file_path)
|
||||
if image_paths:
|
||||
for image_path in image_paths:
|
||||
print(f" Found image: {os.path.basename(image_path)}")
|
||||
image_url = self.upload_image(image_path)
|
||||
if image_url:
|
||||
print(f" Uploaded image: {image_url}")
|
||||
media_urls = [image_url]
|
||||
media_urls.append(image_url)
|
||||
|
||||
# 如果没有 post_id,尝试创建新帖子
|
||||
if not post_id:
|
||||
@@ -582,25 +589,38 @@ class OpenWebUICommunityClient:
|
||||
return f.read()
|
||||
return None
|
||||
|
||||
def _find_image(self, plugin_file_path: str) -> Optional[str]:
|
||||
def _find_images(self, plugin_file_path: str) -> List[str]:
|
||||
"""
|
||||
查找插件对应的图片文件
|
||||
图片名称需要和插件文件名一致(不含扩展名)
|
||||
|
||||
例如:
|
||||
export_to_word.py -> export_to_word.png / export_to_word.jpg
|
||||
支持两种模式:
|
||||
1. 单图模式:图片名称和插件文件名一致(不含扩展名),如 export_to_word.png
|
||||
2. 多图模式:图片名称为 插件名_1.png, 插件名_2.png 等
|
||||
"""
|
||||
plugin_dir = os.path.dirname(plugin_file_path)
|
||||
plugin_name = os.path.splitext(os.path.basename(plugin_file_path))[0]
|
||||
|
||||
# 支持的图片格式
|
||||
image_extensions = [".png", ".jpg", ".jpeg", ".gif", ".webp"]
|
||||
found_images = []
|
||||
|
||||
# 1. 检查单图模式
|
||||
for ext in image_extensions:
|
||||
image_path = os.path.join(plugin_dir, plugin_name + ext)
|
||||
if os.path.exists(image_path):
|
||||
return image_path
|
||||
return None
|
||||
found_images.append(image_path)
|
||||
break # 如果有单图,优先使用单图
|
||||
|
||||
# 2. 检查多图模式 (plugin_name_1, plugin_name_2, ...)
|
||||
# 如果已经找到了单图,就不再寻找多图,除非单图不存在
|
||||
if not found_images:
|
||||
for i in range(1, 11): # 最多支持 10 张
|
||||
for ext in image_extensions:
|
||||
image_path = os.path.join(plugin_dir, f"{plugin_name}_{i}{ext}")
|
||||
if os.path.exists(image_path):
|
||||
found_images.append(image_path)
|
||||
break
|
||||
|
||||
return found_images
|
||||
|
||||
def _inject_id_to_file(self, file_path: str, post_id: str) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user