/** * API 客户端 */ import axios, { AxiosInstance } from 'axios' import type { VideoReviewRequest, VideoReviewResponse, ReviewProgressResponse, ReviewResultResponse, } from '@/types/review' import type { TaskResponse, TaskListResponse, TaskScriptUploadRequest, TaskVideoUploadRequest, } from '@/types/task' const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:8000' class ApiClient { private client: AxiosInstance private tenantId: string = 'default' constructor() { this.client = axios.create({ baseURL: `${API_BASE_URL}/api/v1`, timeout: 30000, headers: { 'Content-Type': 'application/json', }, }) // 请求拦截器:添加租户 ID this.client.interceptors.request.use((config) => { config.headers['X-Tenant-ID'] = this.tenantId return config }) // 响应拦截器:统一错误处理 this.client.interceptors.response.use( (response) => response, (error) => { const message = error.response?.data?.detail || error.message || '请求失败' return Promise.reject(new Error(message)) } ) } setTenantId(tenantId: string) { this.tenantId = tenantId } // ==================== 视频审核 ==================== /** * 提交视频审核 */ async submitVideoReview(data: VideoReviewRequest): Promise { const response = await this.client.post('/videos/review', { video_url: data.videoUrl, platform: data.platform, brand_id: data.brandId, creator_id: data.creatorId, }) return response.data } /** * 查询审核进度 */ async getReviewProgress(reviewId: string): Promise { const response = await this.client.get( `/videos/review/${reviewId}/progress` ) return response.data } /** * 查询审核结果 */ async getReviewResult(reviewId: string): Promise { const response = await this.client.get( `/videos/review/${reviewId}/result` ) return response.data } // ==================== 审核任务 ==================== /** * 查询任务列表 */ async listTasks(page: number = 1, pageSize: number = 20): Promise { const response = await this.client.get('/tasks', { params: { page, page_size: pageSize }, }) return response.data } /** * 查询任务详情 */ async getTask(taskId: string): Promise { const response = await this.client.get(`/tasks/${taskId}`) return response.data } /** * 上传/更新任务脚本 */ async uploadTaskScript(taskId: string, payload: TaskScriptUploadRequest): Promise { const response = await this.client.post(`/tasks/${taskId}/script`, payload) return response.data } /** * 上传/更新任务视频 */ async uploadTaskVideo(taskId: string, payload: TaskVideoUploadRequest): Promise { const response = await this.client.post(`/tasks/${taskId}/video`, payload) return response.data } // ==================== 健康检查 ==================== /** * 健康检查 */ async healthCheck(): Promise<{ status: string; version: string }> { const response = await this.client.get('/health') return response.data } } // 单例导出 export const api = new ApiClient() export default api