Files
sionrui/frontend/app/web-gold/src/api/common.js
sion123 36195ea55a feat: 重构 IdentifyFace.vue 为 Hooks 架构
- 新增 hooks/ 目录,包含三个专用 Hook:
  * useVoiceGeneration - 语音生成和校验逻辑
  * useDigitalHumanGeneration - 数字人视频生成逻辑
  * useIdentifyFaceController - 协调两个子 Hook 的控制器

- 新增 types/identify-face.ts 完整类型定义

- 重构 IdentifyFace.vue 使用 hooks 架构:
  * 视图层与业务逻辑分离
  * 状态管理清晰化
  * 模块解耦,逻辑清晰

- 遵循单一职责原则,每个 Hook 只负责一个领域
- 提升代码可测试性和可维护性
- 支持两种视频素材来源:素材库选择和直接上传
- 实现语音生成优先校验的业务规则

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-28 00:19:17 +08:00

86 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 应用层 API 服务
* 封装应用特定的 API 调用,使用 mono 级别的服务
*/
import { fetchEventSource } from '@microsoft/fetch-event-source'
// 直接使用实例(最简单、最可靠)
import tokenManager from '@gold/utils/token-manager'
import { TikHubService } from '@gold/api/services'
import { API_BASE } from '@gold/config/api'
/**
* TikHub API 基础路径
*/
const TIKHUB_BASE = API_BASE.TIKHUB_APP || API_BASE.TIKHUB || ''
/**
* 应用层通用服务
*/
export const CommonService = {
/**
* 视频转字符(音频转文字)
* 直接使用 mono 级别的 TikHub 服务
*/
videoToCharacters(data) {
return TikHubService.videoToCharacters(data)
},
/**
* 调用工作流
*/
callWorkflow(data) {
return TikHubService.callWorkflow(data)
},
/**
* 流式调用工作流SSE
*/
async callWorkflowStream(options) {
const {
data,
ctrl,
onMessage,
onError,
onClose
} = options || {}
const authHeader = tokenManager.getAuthHeader()
let retryCount = 0
const maxRetries = 0
return fetchEventSource(`${TIKHUB_BASE}/callWorkflow`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
...(authHeader ? { Authorization: authHeader } : {})
},
openWhenHidden: true,
body: JSON.stringify(data),
onmessage: onMessage,
onerror: (err) => {
retryCount++
if (typeof onError === 'function') {
onError(err)
}
if (retryCount > maxRetries) {
throw err
}
},
onclose: () => {
if (typeof onClose === 'function') {
onClose()
}
},
signal: ctrl ? ctrl.signal : undefined
})
}
}
export default CommonService