211 lines
4.7 KiB
TypeScript
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.

/**
* 视频编辑功能配置
*/
export interface VideoEditApiConfig {
/** 是否使用Mock API */
useMockApi: boolean;
/** 是否使用本地API路由 */
useLocalApi: boolean;
/** 远程API基础URL */
remoteApiBase: string;
/** 本地API基础URL */
localApiBase: string;
/** API超时时间毫秒 */
timeout: number;
/** 是否启用调试日志 */
enableDebugLog: boolean;
}
/**
* 默认配置
*/
export const defaultVideoEditApiConfig: VideoEditApiConfig = {
useMockApi: true, // 优先使用Mock API确保前端功能独立
useLocalApi: true, // 备用本地API路由
remoteApiBase: '/video-edit',
localApiBase: '/api/video-edit',
timeout: 10000,
enableDebugLog: process.env.NODE_ENV === 'development'
};
/**
* 获取当前API配置
*/
export function getVideoEditApiConfig(): VideoEditApiConfig {
// 可以从环境变量或其他配置源读取
const config = { ...defaultVideoEditApiConfig };
// 环境变量覆盖
if (process.env.NEXT_PUBLIC_VIDEO_EDIT_USE_MOCK === 'true') {
config.useMockApi = true;
config.useLocalApi = false;
}
if (process.env.NEXT_PUBLIC_VIDEO_EDIT_USE_REMOTE === 'true') {
config.useLocalApi = false;
config.useMockApi = false;
}
if (process.env.NEXT_PUBLIC_VIDEO_EDIT_REMOTE_BASE) {
config.remoteApiBase = process.env.NEXT_PUBLIC_VIDEO_EDIT_REMOTE_BASE;
}
return config;
}
/**
* 获取API端点URL
*/
export function getApiEndpoint(path: string): string {
const config = getVideoEditApiConfig();
if (config.useMockApi) {
return ''; // Mock API不需要真实端点
}
if (config.useLocalApi) {
return `${config.localApiBase}${path}`;
}
return `${config.remoteApiBase}${path}`;
}
/**
* 调试日志函数
*/
export function debugLog(message: string, data?: any): void {
const config = getVideoEditApiConfig();
if (config.enableDebugLog) {
console.log(`[VideoEdit] ${message}`, data || '');
}
}
/**
* API状态检查
*/
export async function checkApiHealth(): Promise<{
status: 'healthy' | 'unhealthy' | 'unknown';
message: string;
responseTime?: number;
}> {
const config = getVideoEditApiConfig();
if (config.useMockApi) {
return {
status: 'healthy',
message: 'Mock API is always healthy',
responseTime: 0
};
}
try {
const startTime = Date.now();
const endpoint = getApiEndpoint('/health');
// 尝试健康检查端点
const response = await fetch(endpoint, {
method: 'GET',
timeout: config.timeout
} as any);
const responseTime = Date.now() - startTime;
if (response.ok) {
return {
status: 'healthy',
message: 'API is responding normally',
responseTime
};
} else {
return {
status: 'unhealthy',
message: `API returned status ${response.status}`,
responseTime
};
}
} catch (error) {
return {
status: 'unhealthy',
message: error instanceof Error ? error.message : 'Unknown error',
};
}
}
/**
* 错误处理配置
*/
export const errorHandlingConfig = {
/** 最大重试次数 */
maxRetries: 3,
/** 重试延迟(毫秒) */
retryDelay: 1000,
/** 是否在API失败时自动回退到Mock */
fallbackToMock: true,
/** 错误通知配置 */
notifications: {
showNetworkErrors: true,
showValidationErrors: true,
showServerErrors: true
}
};
/**
* 性能监控配置
*/
export const performanceConfig = {
/** 是否启用性能监控 */
enabled: process.env.NODE_ENV === 'development',
/** 慢请求阈值(毫秒) */
slowRequestThreshold: 2000,
/** 是否记录所有请求 */
logAllRequests: false,
/** 是否启用请求缓存 */
enableCaching: true,
/** 缓存过期时间(毫秒) */
cacheExpiry: 5 * 60 * 1000 // 5分钟
};
/**
* 功能开关配置
*/
export const featureFlags = {
/** 是否启用编辑点创建 */
enableCreateEditPoint: true,
/** 是否启用编辑点更新 */
enableUpdateEditPoint: true,
/** 是否启用编辑点删除 */
enableDeleteEditPoint: true,
/** 是否启用批量操作 */
enableBatchOperations: true,
/** 是否启用实时同步 */
enableRealTimeSync: false,
/** 是否启用离线模式 */
enableOfflineMode: false
};
/**
* UI配置
*/
export const uiConfig = {
/** 编辑点最大数量 */
maxEditPoints: 20,
/** 描述最大长度 */
maxDescriptionLength: 500,
/** 是否显示调试信息 */
showDebugInfo: process.env.NODE_ENV === 'development',
/** 动画配置 */
animations: {
enabled: true,
duration: 300,
easing: 'ease-out'
},
/** 主题配置 */
theme: {
primaryColor: '#3b82f6',
successColor: '#10b981',
errorColor: '#ef4444',
warningColor: '#f59e0b'
}
};