fix: react hook

This commit is contained in:
root
2025-07-13 00:29:04 +08:00
parent 0b9d9d3f3d
commit 2bca550848
5 changed files with 198 additions and 22 deletions

View File

@@ -5,6 +5,7 @@
from pathlib import Path
from typing import Optional, List
from dataclasses import asdict
from datetime import datetime
import typer
from python_core.utils.jsonrpc_enhanced import create_response_handler, create_progress_reporter
from python_core.services.template_manager_cloud import TemplateManagerCloud, TemplateInfo
@@ -454,6 +455,82 @@ def get_popular_tags(
response.error(-32603, f"获取热门标签失败: {str(e)}")
@template_app.command("update-segment")
def update_segment_name(
template_id: str = typer.Argument(..., help="模板ID"),
segment_id: str = typer.Argument(..., help="片段ID"),
new_name: str = typer.Argument(..., help="新名称"),
user_id: Optional[str] = typer.Option(None, "--user-id", help="用户ID"),
verbose: bool = typer.Option(False, "--verbose", "-v", help="详细输出"),
json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
):
"""更新模板片段名称"""
response = create_response_handler()
try:
# 使用 PostgreSQL 模板表
from python_core.database.template_postgres import template_table
# 获取模板
template = template_table.get_template_by_id(template_id)
if not template:
response.error(-32604, f"模板不存在: {template_id}")
return
# 检查权限
if user_id and template.user_id != user_id:
response.error(-32605, f"无权限修改模板: {template_id}")
return
# 获取 draft_content
draft_content = template_table.get_draft_content(template_id)
if draft_content is None:
response.error(-32606, f"模板详细信息不存在: {template_id}")
return
# 确保 draft_content 是字典类型
if not isinstance(draft_content, dict):
draft_content = {}
# 查找并更新片段名称
updated = False
tracks_data = draft_content.get('tracks', [])
for track in tracks_data:
if isinstance(track, dict):
segments = track.get('segments', [])
for segment in segments:
if isinstance(segment, dict) and segment.get('id') == segment_id:
segment['name'] = new_name
updated = True
break
if updated:
break
if not updated:
response.error(-32607, f"片段不存在: {segment_id}")
return
# 更新数据库中的 draft_content
success = template_table.update_template(template_id, {
'draft_content': draft_content,
'updated_at': datetime.now().isoformat()
})
if success:
response.success({
'template_id': template_id,
'segment_id': segment_id,
'new_name': new_name,
'updated': True
})
else:
response.error(-32608, "更新失败")
except Exception as e:
logger.error(f"更新片段名称失败: {e}")
response.error(-32603, f"更新片段名称失败: {str(e)}")
@template_app.command("by-tag")
def get_templates_by_tag(
tag: str = typer.Argument(..., help="标签名称"),
@@ -468,7 +545,7 @@ def get_templates_by_tag(
try:
# 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default")
# 根据标签获取模板
templates = manager.get_templates_by_tag(tag, include_cloud=include_cloud, limit=limit)