feat: implement auto-sync plugin ID on publish
This commit is contained in:
@@ -25,6 +25,8 @@ Every plugin **MUST** have bilingual versions for both code and documentation:
|
|||||||
- **Valves**: Use `pydantic` for configuration.
|
- **Valves**: Use `pydantic` for configuration.
|
||||||
- **Database**: Re-use `open_webui.internal.db` shared connection.
|
- **Database**: Re-use `open_webui.internal.db` shared connection.
|
||||||
- **User Context**: Use `_get_user_context` helper method.
|
- **User Context**: Use `_get_user_context` helper method.
|
||||||
|
- **Chat Context**: Use `_get_chat_context` helper method for `chat_id` and `message_id`.
|
||||||
|
- **Debugging**: Use `_emit_debug_log` for frontend console logging (requires `SHOW_DEBUG_LOG` valve).
|
||||||
- **Chat API**: For message updates, follow the "OpenWebUI Chat API 更新规范" in `.github/copilot-instructions.md`.
|
- **Chat API**: For message updates, follow the "OpenWebUI Chat API 更新规范" in `.github/copilot-instructions.md`.
|
||||||
- Use Event API for immediate UI updates
|
- Use Event API for immediate UI updates
|
||||||
- Use Chat Persistence API for database storage
|
- Use Chat Persistence API for database storage
|
||||||
@@ -86,6 +88,7 @@ Reference: `.github/workflows/release.yml`
|
|||||||
- Workflow: `.github/workflows/publish_plugin.yml`
|
- Workflow: `.github/workflows/publish_plugin.yml`
|
||||||
- Trigger: Release published.
|
- Trigger: Release published.
|
||||||
- Action: Automatically updates the plugin code and metadata on OpenWebUI.com using `scripts/publish_plugin.py`.
|
- Action: Automatically updates the plugin code and metadata on OpenWebUI.com using `scripts/publish_plugin.py`.
|
||||||
|
- **Auto-Sync**: If a local plugin has no ID but matches an existing published plugin by **Title**, the script will automatically fetch the ID, update the local file, and proceed with the update.
|
||||||
- Requirement: `OPENWEBUI_API_KEY` secret must be set.
|
- Requirement: `OPENWEBUI_API_KEY` secret must be set.
|
||||||
|
|
||||||
### Pull Request Check
|
### Pull Request Check
|
||||||
|
|||||||
@@ -483,25 +483,44 @@ class OpenWebUICommunityClient:
|
|||||||
print(f" Uploaded image: {image_url}")
|
print(f" Uploaded image: {image_url}")
|
||||||
media_urls = [image_url]
|
media_urls = [image_url]
|
||||||
|
|
||||||
# 如果没有 post_id,尝试创建新帖子
|
# 如果没有 post_id,尝试查找或创建
|
||||||
if not post_id:
|
if not post_id:
|
||||||
if not auto_create:
|
# 1. 尝试通过标题查找已存在的帖子
|
||||||
return False, "No openwebui_id found and auto_create is disabled"
|
print(f" Searching for existing post with title: {title}")
|
||||||
|
try:
|
||||||
|
all_posts = self.get_all_posts()
|
||||||
|
existing_post = next(
|
||||||
|
(p for p in all_posts if p.get("title") == title), None
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f" Warning: Failed to fetch posts for title check: {e}")
|
||||||
|
existing_post = None
|
||||||
|
|
||||||
print(f" Creating new post for: {title}")
|
if existing_post:
|
||||||
new_post_id = self.create_plugin(
|
post_id = existing_post.get("id")
|
||||||
title=title,
|
print(f" Found existing post: {title} (ID: {post_id})")
|
||||||
source_code=content,
|
self._inject_id_to_file(file_path, post_id)
|
||||||
readme_content=readme_content or metadata.get("description", ""),
|
# post_id 已设置,后续将进入更新流程
|
||||||
metadata=metadata,
|
|
||||||
media_urls=media_urls,
|
|
||||||
)
|
|
||||||
|
|
||||||
if new_post_id:
|
else:
|
||||||
# 将新 ID 写回本地文件
|
# 2. 如果没找到,且允许自动创建,则创建
|
||||||
self._inject_id_to_file(file_path, new_post_id)
|
if not auto_create:
|
||||||
return True, f"Created new post (ID: {new_post_id})"
|
return False, "No openwebui_id found and auto_create is disabled"
|
||||||
return False, "Failed to create new post"
|
|
||||||
|
print(f" Creating new post for: {title}")
|
||||||
|
new_post_id = self.create_plugin(
|
||||||
|
title=title,
|
||||||
|
source_code=content,
|
||||||
|
readme_content=readme_content or metadata.get("description", ""),
|
||||||
|
metadata=metadata,
|
||||||
|
media_urls=media_urls,
|
||||||
|
)
|
||||||
|
|
||||||
|
if new_post_id:
|
||||||
|
# 将新 ID 写回本地文件
|
||||||
|
self._inject_id_to_file(file_path, new_post_id)
|
||||||
|
return True, f"Created new post (ID: {new_post_id})"
|
||||||
|
return False, "Failed to create new post"
|
||||||
|
|
||||||
# 获取远程帖子信息(只需获取一次)
|
# 获取远程帖子信息(只需获取一次)
|
||||||
remote_post = None
|
remote_post = None
|
||||||
|
|||||||
Reference in New Issue
Block a user