From 8a497afa47c9e5612b34f9afb95aa99d97e7a9b1 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Jul 2025 13:20:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=A4=84=E7=90=86=E6=9C=8D=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=20JSON-RPC=20=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔧 前端修复: 1. 批量处理服务 JSON-RPC 支持: - 为 batchGenerateVideos 添加 JSON-RPC 2.0 格式解析 - 检测 jsonrpc: '2.0' 并提取 result 字段 - 处理 JSON-RPC 错误响应 - 保持向后兼容直接 JSON 格式 2. 详细的调试日志: - 添加批量请求和响应的详细日志 - 显示原始和解析后的结果 - 区分 JSON-RPC 成功和错误响应 - 便于问题排查和调试 3. Store 状态判断增强: - 添加详细的状态检查日志 - 显示 result.status 的值和类型 - 记录成功和失败的处理路径 - 帮助诊断状态识别问题 4. 错误处理统一: - 批量处理和单个处理使用相同的 JSON-RPC 解析逻辑 - 统一的错误信息格式 - 完整的错误详情记录 🎯 问题解决: - 批量处理服务缺少 JSON-RPC 解析 → 添加完整解析逻辑 ✓ - 前端显示失败状态 → 正确提取 JSON-RPC result ✓ - 调试信息不足 → 添加详细日志 ✓ ✅ 修复效果: - 批量处理正确解析 JSON-RPC 响应 - 前端能够识别批量任务的真实状态 - 详细的调试信息便于问题排查 - 统一的 JSON-RPC 处理逻辑 现在批量处理应该能正确显示成功状态! --- src/services/tauri.ts | 27 ++++++++++++++++++++++++++- src/stores/useAIVideoStore.ts | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/services/tauri.ts b/src/services/tauri.ts index f34ab2d..12b1131 100644 --- a/src/services/tauri.ts +++ b/src/services/tauri.ts @@ -420,10 +420,35 @@ export class AIVideoService { */ static async batchGenerateVideos(request: BatchAIVideoRequest): Promise { try { + console.log('Sending batch AI video request:', request) const result = await invoke('batch_generate_ai_videos', { request }) - return JSON.parse(result as string) + console.log('Raw batch result from Tauri:', result) + + const parsedResult = JSON.parse(result as string) + console.log('Parsed batch result:', parsedResult) + + // Handle JSON-RPC response format + if (parsedResult.jsonrpc === "2.0") { + if (parsedResult.result) { + // Success response + console.log('JSON-RPC batch success result:', parsedResult.result) + return parsedResult.result + } else if (parsedResult.error) { + // Error response + console.error('JSON-RPC batch error:', parsedResult.error) + throw new Error(parsedResult.error.message || 'JSON-RPC batch error') + } + } + + // Fallback: direct result format + return parsedResult } catch (error) { console.error('Failed to batch generate AI videos:', error) + console.error('Batch error details:', { + name: error instanceof Error ? error.name : 'Unknown', + message: error instanceof Error ? error.message : String(error), + stack: error instanceof Error ? error.stack : undefined + }) throw error } } diff --git a/src/stores/useAIVideoStore.ts b/src/stores/useAIVideoStore.ts index 89dc50f..1b36b34 100644 --- a/src/stores/useAIVideoStore.ts +++ b/src/stores/useAIVideoStore.ts @@ -173,9 +173,13 @@ export const useAIVideoStore = create((set, get) => ({ updateJob(jobId, { status: 'processing', progress: 0 }) const result = await AIVideoService.batchGenerateVideos(request) + console.log('Batch processing result in store:', result) + console.log('Result status:', result?.status) + console.log('Result type:', typeof result?.status) // Check if the Python script actually succeeded if (result && result.status === true) { + console.log('Batch processing succeeded, updating job to completed') updateJob(jobId, { status: 'completed', progress: 100, @@ -184,6 +188,7 @@ export const useAIVideoStore = create((set, get) => ({ }) } else { // Python script returned failure + console.log('Batch processing failed, result:', result) const errorMsg = result?.msg || 'Batch processing failed' updateJob(jobId, { status: 'failed',