fix: 模板片段信息
This commit is contained in:
parent
b07992a82a
commit
629b4dd42b
|
|
@ -368,6 +368,80 @@ class TemplateManager:
|
|||
logger.error(f"Failed to delete template {template_id}: {e}")
|
||||
return False
|
||||
|
||||
def get_template_detail(self, template_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Get detailed template information including tracks and segments
|
||||
|
||||
Args:
|
||||
template_id: Template ID
|
||||
|
||||
Returns:
|
||||
Dict containing detailed template information with tracks and segments
|
||||
"""
|
||||
try:
|
||||
# Get basic template info
|
||||
template = self.get_template(template_id)
|
||||
if not template:
|
||||
return None
|
||||
|
||||
# Load draft content to get tracks and segments
|
||||
draft_content_path = Path(template.draft_content_path)
|
||||
if not draft_content_path.exists():
|
||||
logger.error(f"Draft content file not found: {draft_content_path}")
|
||||
return None
|
||||
|
||||
with open(draft_content_path, 'r', encoding='utf-8') as f:
|
||||
draft_content = json.load(f)
|
||||
|
||||
# Extract tracks and segments information
|
||||
tracks = []
|
||||
if 'tracks' in draft_content:
|
||||
for track_data in draft_content['tracks']:
|
||||
track = {
|
||||
'id': track_data.get('id', ''),
|
||||
'name': track_data.get('name', f"Track {track_data.get('index', 0) + 1}"),
|
||||
'type': track_data.get('type', 'video'),
|
||||
'index': track_data.get('index', 0),
|
||||
'segments': [],
|
||||
'properties': track_data.get('properties', {})
|
||||
}
|
||||
|
||||
# Extract segments
|
||||
if 'segments' in track_data:
|
||||
for segment_data in track_data['segments']:
|
||||
segment = {
|
||||
'id': segment_data.get('id', ''),
|
||||
'type': segment_data.get('type', 'video'),
|
||||
'name': segment_data.get('name', 'Unnamed Segment'),
|
||||
'start_time': segment_data.get('start_time', 0),
|
||||
'end_time': segment_data.get('end_time', 0),
|
||||
'duration': segment_data.get('duration', 0),
|
||||
'resource_path': segment_data.get('resource_path', ''),
|
||||
'properties': segment_data.get('properties', {}),
|
||||
'effects': segment_data.get('effects', [])
|
||||
}
|
||||
track['segments'].append(segment)
|
||||
|
||||
tracks.append(track)
|
||||
|
||||
# Build detailed template information
|
||||
detail = {
|
||||
'id': template.id,
|
||||
'name': template.name,
|
||||
'description': template.description,
|
||||
'canvas_config': template.canvas_config,
|
||||
'tracks': tracks,
|
||||
'duration': template.duration,
|
||||
'fps': draft_content.get('fps', 30),
|
||||
'sample_rate': draft_content.get('sample_rate')
|
||||
}
|
||||
|
||||
return detail
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get template detail for {template_id}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
"""Command line interface for template management."""
|
||||
|
|
@ -474,6 +548,21 @@ def main():
|
|||
else:
|
||||
rpc.error(JSONRPCError.TEMPLATE_NOT_FOUND, "Failed to delete template")
|
||||
|
||||
elif args.action == "get_template_detail":
|
||||
if not args.template_id:
|
||||
rpc.error(JSONRPCError.INVALID_PARAMS, "Template ID is required")
|
||||
return
|
||||
|
||||
detail = manager.get_template_detail(args.template_id)
|
||||
if detail:
|
||||
result = {
|
||||
"status": True,
|
||||
"detail": detail
|
||||
}
|
||||
rpc.success(result)
|
||||
else:
|
||||
rpc.error(JSONRPCError.TEMPLATE_NOT_FOUND, f"Template detail not found: {args.template_id}")
|
||||
|
||||
else:
|
||||
rpc.error(JSONRPCError.METHOD_NOT_FOUND, f"Unknown action: {args.action}")
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ export interface UseProgressCommandOptions {
|
|||
autoReset?: boolean // Auto reset state after completion
|
||||
}
|
||||
|
||||
export interface UseProgressCommandReturn {
|
||||
export interface UseProgressCommandReturn<T> {
|
||||
// State
|
||||
isExecuting: boolean
|
||||
progress: ProgressState | null
|
||||
result: any
|
||||
result: T
|
||||
error: Error | null
|
||||
logs: string[]
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ export interface UseProgressCommandReturn {
|
|||
* @param options - Configuration options
|
||||
* @returns Hook state and actions
|
||||
*/
|
||||
export function useProgressCommand(options: UseProgressCommandOptions = {}): UseProgressCommandReturn {
|
||||
export function useProgressCommand<T>(options: UseProgressCommandOptions = {}): UseProgressCommandReturn<T> {
|
||||
const [isExecuting, setIsExecuting] = useState(false)
|
||||
const [progress, setProgress] = useState<ProgressState | null>(null)
|
||||
const [result, setResult] = useState<any>(null)
|
||||
|
|
@ -74,7 +74,7 @@ export function useProgressCommand(options: UseProgressCommandOptions = {}): Use
|
|||
setIsExecuting(true)
|
||||
setError(null)
|
||||
setResult(null)
|
||||
|
||||
|
||||
if (options.autoReset !== false) {
|
||||
setProgress(null)
|
||||
setLogs([])
|
||||
|
|
@ -130,8 +130,36 @@ export function useProgressCommand(options: UseProgressCommandOptions = {}): Use
|
|||
/**
|
||||
* Specialized hook for template operations
|
||||
*/
|
||||
|
||||
export interface TemplateInfo {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
thumbnail_path: string
|
||||
draft_content_path: string
|
||||
resources_path: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
canvas_config: any
|
||||
duration: number
|
||||
material_count: number
|
||||
track_count: number
|
||||
tags: string[]
|
||||
}
|
||||
export interface ImportResult {
|
||||
status: boolean
|
||||
msg: string
|
||||
imported_count: number
|
||||
failed_count: number
|
||||
imported_templates: TemplateInfo[]
|
||||
failed_templates: Array<{
|
||||
name: string
|
||||
error: string
|
||||
}>
|
||||
}
|
||||
|
||||
export function useTemplateProgress(options: UseProgressCommandOptions = {}) {
|
||||
const hook = useProgressCommand(options)
|
||||
const hook = useProgressCommand<ImportResult>(options)
|
||||
|
||||
const batchImport = useCallback(async (sourceFolder: string) => {
|
||||
return hook.execute(
|
||||
|
|
|
|||
|
|
@ -4,21 +4,6 @@ import { invoke } from '@tauri-apps/api/core'
|
|||
import { TemplateService } from '../services/tauri'
|
||||
import { useTemplateProgress } from '../hooks/useProgressCommand'
|
||||
|
||||
interface TemplateInfo {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
thumbnail_path: string
|
||||
draft_content_path: string
|
||||
resources_path: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
canvas_config: any
|
||||
duration: number
|
||||
material_count: number
|
||||
track_count: number
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
// 轨道和片段的数据结构
|
||||
interface TrackSegment {
|
||||
|
|
@ -54,19 +39,8 @@ interface TemplateDetail {
|
|||
}
|
||||
|
||||
// Import the progress interface from the hook
|
||||
import type { ProgressState } from '../hooks/useProgressCommand'
|
||||
import type { ProgressState, TemplateInfo } from '../hooks/useProgressCommand'
|
||||
|
||||
interface ImportResult {
|
||||
status: boolean
|
||||
msg: string
|
||||
imported_count: number
|
||||
failed_count: number
|
||||
imported_templates: TemplateInfo[]
|
||||
failed_templates: Array<{
|
||||
name: string
|
||||
error: string
|
||||
}>
|
||||
}
|
||||
|
||||
const TemplateManagePage: React.FC = () => {
|
||||
const [templates, setTemplates] = useState<TemplateInfo[]>([])
|
||||
|
|
@ -283,7 +257,7 @@ const TemplateManagePage: React.FC = () => {
|
|||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setImportResult(null)}
|
||||
onClick={() => resetImport()}
|
||||
className="text-gray-400 hover:text-gray-600"
|
||||
>
|
||||
×
|
||||
|
|
|
|||
Loading…
Reference in New Issue