diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index ba9a6cd..f82c2b9 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -22,12 +22,12 @@ const Sidebar: React.FC = () => { { path: '/', icon: Home, label: '首页' }, { path: '/editor', icon: Video, label: '编辑器' }, { path: '/ai-video', icon: Sparkles, label: 'AI 视频' }, - { path: '/templates', icon: Layout, label: '模板管理' }, + { path: '/templates', icon: Layout, label: '模板库' }, { path: '/resource-categories', icon: Tags, label: '分类管理' }, - { path: '/projects', icon: FolderOpen, label: '项目' }, - { path: '/models', icon: User, label: '模特管理' }, + { path: '/projects', icon: FolderOpen, label: '项目库' }, + { path: '/models', icon: User, label: '模特库' }, { path: '/media', icon: Image, label: '媒体库' }, - { path: '/audio', icon: Music, label: '音频' }, + { path: '/audio', icon: Music, label: '音频库' }, { path: '/settings', icon: Settings, label: '设置' }, ] diff --git a/src/services/modelService.ts b/src/services/modelService.ts index 8e0639c..d445d88 100644 --- a/src/services/modelService.ts +++ b/src/services/modelService.ts @@ -26,30 +26,28 @@ export interface ApiResponse { } export class ModelService { + /** + * 尝试解析JSON响应 + */ + private static tryJsonParse(result: any): any { + if (typeof result === 'string') { + try { + const parsed = JSON.parse(result) + return parsed.result || parsed + } catch (error) { + console.error('Failed to parse JSON:', error) + return result + } + } + return result + } /** * 获取所有模特 */ static async getAllModels(): Promise> { try { - console.log('Calling get_all_models...') const result = await invoke('get_all_models') - console.log('Raw result from Tauri:', result) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - console.log('Parsed result:', parsed) - return parsed as ApiResponse - } catch (parseError) { - console.error('Failed to parse JSON response:', parseError) - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to get all models:', error) return { @@ -65,20 +63,7 @@ export class ModelService { static async getModelById(modelId: string): Promise> { try { const result = await invoke('get_model_by_id', { modelId }) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - return parsed as ApiResponse - } catch (parseError) { - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to get model by id:', error) return { @@ -93,25 +78,8 @@ export class ModelService { */ static async createModel(request: CreateModelRequest): Promise> { try { - console.log('Calling create_model with:', request) const result = await invoke('create_model', { request }) - console.log('Raw result from Tauri:', result) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - console.log('Parsed result:', parsed) - return parsed as ApiResponse - } catch (parseError) { - console.error('Failed to parse JSON response:', parseError) - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to create model:', error) return { @@ -125,25 +93,12 @@ export class ModelService { * 更新模特 */ static async updateModel( - modelId: string, + modelId: string, request: UpdateModelRequest ): Promise> { try { const result = await invoke('update_model', { modelId, request }) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - return parsed as ApiResponse - } catch (parseError) { - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to update model:', error) return { @@ -159,20 +114,7 @@ export class ModelService { static async deleteModel(modelId: string): Promise> { try { const result = await invoke('delete_model', { modelId }) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - return parsed as ApiResponse - } catch (parseError) { - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to delete model:', error) return { @@ -188,20 +130,7 @@ export class ModelService { static async searchModels(keyword: string): Promise> { try { const result = await invoke('search_models', { keyword }) - - if (typeof result === 'string') { - try { - const parsed = JSON.parse(result) - return parsed as ApiResponse - } catch (parseError) { - return { - status: false, - msg: `Invalid JSON response: ${result}` - } - } - } - - return result as ApiResponse + return { status: true, msg: 'ok', data: this.tryJsonParse(result) } as ApiResponse } catch (error) { console.error('Failed to search models:', error) return {