From 35f19390304ac828843c4ad65fff024851ac660a Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 26 Jul 2026 17:11:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(api):=20=E6=8B=86=E5=88=86=20voices.ts?= =?UTF-8?q?=20=E4=B8=BA=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=EF=BC=88types/?= =?UTF-8?q?voices/index=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 145 行的 voices.ts 拆分为目录化结构: - types.ts: 类型定义(统一音色/预设音色/旧接口类型) - voices.ts: 全部 7 个 API 函数(新统一音色 + 旧接口兼容) - index.ts: 统一入口 re-export,保持 @/api/voices 路径向后兼容 主入口从 145 行减少到约 30 行,按职责清晰分层。 --- apps/web/src/api/voices/index.ts | 26 +++++++ apps/web/src/api/voices/types.ts | 81 +++++++++++++++++++++ apps/web/src/api/{ => voices}/voices.ts | 93 +++---------------------- 3 files changed, 116 insertions(+), 84 deletions(-) create mode 100644 apps/web/src/api/voices/index.ts create mode 100644 apps/web/src/api/voices/types.ts rename apps/web/src/api/{ => voices}/voices.ts (54%) diff --git a/apps/web/src/api/voices/index.ts b/apps/web/src/api/voices/index.ts new file mode 100644 index 000000000..182aa7d31 --- /dev/null +++ b/apps/web/src/api/voices/index.ts @@ -0,0 +1,26 @@ +/** + * 配音相关 API — 目录化入口 + * 保持与原 voices.ts 相同导出,向后兼容 + */ + +// 类型 +export type { + UnifiedVoiceItem, + UnifiedVoiceListResponse, + PresetVoiceItem, + PresetVoiceListResponse, + UnifiedVoiceListParams, + VoiceItem, + CreateVoiceRequest, +} from "./types" + +// API 函数 +export { + fetchVoices, + fetchPresetVoices, + getVoices, + createVoice, + updateVoice, + deleteVoice, + generateAIVoice, +} from "./voices" diff --git a/apps/web/src/api/voices/types.ts b/apps/web/src/api/voices/types.ts new file mode 100644 index 000000000..25c10b94b --- /dev/null +++ b/apps/web/src/api/voices/types.ts @@ -0,0 +1,81 @@ +/** + * 配音相关类型定义 + */ + +/** 统一音色条目(preset + clone 混合) */ +export interface UnifiedVoiceItem { + id: string + type: "preset" | "clone" + name: string + description: string + gender: string + language: string + voice_id: string + voice_provider: string + audio_url: string | null + preview_url: string | null + duration: number | null + file_size: number | null + status: string + tags: string[] + user_id: string | null + project_id: string | null + voice_clone_profile_id: string | null + created_at: string | null + updated_at: string | null +} + +/** 统一音色列表响应 */ +export interface UnifiedVoiceListResponse { + items: UnifiedVoiceItem[] + total: number + preset_count: number + clone_count: number +} + +/** 预设音色条目 */ +export interface PresetVoiceItem { + voice_id: string + name: string + description: string + gender: string + language: string + preview_url: string | null + tags: string[] +} + +/** 预设音色列表响应 */ +export interface PresetVoiceListResponse { + items: PresetVoiceItem[] + total: number +} + +/** 统一列表查询参数 */ +export interface UnifiedVoiceListParams { + type?: "preset" | "clone" + status?: string + skip?: number + limit?: number +} + +/** 配音条目(旧) */ +export interface VoiceItem { + id: string + name: string + text: string + voice_type?: string + duration_seconds?: number + storage_key?: string + audio_url?: string + status?: string + is_favorite?: boolean + created_at?: string + updated_at?: string +} + +/** 创建配音请求(旧) */ +export interface CreateVoiceRequest { + name: string + text: string + voice_type?: string +} diff --git a/apps/web/src/api/voices.ts b/apps/web/src/api/voices/voices.ts similarity index 54% rename from apps/web/src/api/voices.ts rename to apps/web/src/api/voices/voices.ts index 7d777606b..9401645c4 100644 --- a/apps/web/src/api/voices.ts +++ b/apps/web/src/api/voices/voices.ts @@ -1,68 +1,15 @@ /** - * 配音相关 API - * Phase 1 新增:全局配音库 - * + * 配音相关 API 函数 * 任务 3.11:新增统一音色 API(对接后端 3.04),保留旧接口向后兼容 */ -import apiClient from "./client" - -/* ── 统一音色 API(后端 3.04) ─────────────────────────── */ - -/** 统一音色条目(preset + clone 混合) */ -export interface UnifiedVoiceItem { - id: string - type: "preset" | "clone" - name: string - description: string - gender: string - language: string - voice_id: string - voice_provider: string - audio_url: string | null - preview_url: string | null - duration: number | null - file_size: number | null - status: string - tags: string[] - user_id: string | null - project_id: string | null - voice_clone_profile_id: string | null - created_at: string | null - updated_at: string | null -} - -/** 统一音色列表响应 */ -export interface UnifiedVoiceListResponse { - items: UnifiedVoiceItem[] - total: number - preset_count: number - clone_count: number -} - -/** 预设音色条目 */ -export interface PresetVoiceItem { - voice_id: string - name: string - description: string - gender: string - language: string - preview_url: string | null - tags: string[] -} - -/** 预设音色列表响应 */ -export interface PresetVoiceListResponse { - items: PresetVoiceItem[] - total: number -} - -/** 统一列表查询参数 */ -export interface UnifiedVoiceListParams { - type?: "preset" | "clone" - status?: string - skip?: number - limit?: number -} +import apiClient from "../client" +import type { + CreateVoiceRequest, + PresetVoiceListResponse, + UnifiedVoiceListParams, + UnifiedVoiceListResponse, + VoiceItem, +} from "./types" /** 获取统一音色列表(推荐) */ export const fetchVoices = async ( @@ -86,28 +33,6 @@ export const fetchPresetVoices = async (): Promise => { /* ── 向后兼容(旧接口) ────────────────────────────────── */ -/** 配音条目(旧) */ -export interface VoiceItem { - id: string - name: string - text: string - voice_type?: string - duration_seconds?: number - storage_key?: string - audio_url?: string - status?: string - is_favorite?: boolean - created_at?: string - updated_at?: string -} - -/** 创建配音请求(旧) */ -export interface CreateVoiceRequest { - name: string - text: string - voice_type?: string -} - /** 获取当前用户的所有配音(旧 → /voices/legacy) */ export const getVoices = async (): Promise => { const response = await apiClient.get("/voices/legacy") -- 2.54.0