Files
CC-Switch/src/lib/api/failover.ts
T
YoVinchen e093164b8d feat(frontend): add failover API layer and TanStack Query hooks
Add frontend data layer for failover management:

- Add failover.ts API: Tauri invoke wrappers for all failover commands
- Add failover.ts query hooks: TanStack Query mutations and queries
  - useProxyTargets, useProviderHealth queries
  - useSetProxyTarget, useResetCircuitBreaker mutations
  - useCircuitBreakerConfig query and mutation
- Update queries.ts with provider health query key
- Update mutations.ts to invalidate health on provider changes
- Add CircuitBreakerConfig and ProviderHealth types
2025-12-08 11:09:19 +08:00

74 lines
1.8 KiB
TypeScript

import { invoke } from "@tauri-apps/api/core";
import type {
ProviderHealth,
CircuitBreakerConfig,
CircuitBreakerStats,
} from "@/types/proxy";
export interface Provider {
id: string;
name: string;
settingsConfig: unknown;
websiteUrl?: string;
category?: string;
createdAt?: number;
sortIndex?: number;
notes?: string;
meta?: unknown;
icon?: string;
iconColor?: string;
isProxyTarget?: boolean;
}
export const failoverApi = {
// 获取代理目标列表
async getProxyTargets(appType: string): Promise<Provider[]> {
return invoke("get_proxy_targets", { appType });
},
// 设置代理目标
async setProxyTarget(
providerId: string,
appType: string,
enabled: boolean,
): Promise<void> {
return invoke("set_proxy_target", { providerId, appType, enabled });
},
// 获取供应商健康状态
async getProviderHealth(
providerId: string,
appType: string,
): Promise<ProviderHealth> {
return invoke("get_provider_health", { providerId, appType });
},
// 重置熔断器
async resetCircuitBreaker(
providerId: string,
appType: string,
): Promise<void> {
return invoke("reset_circuit_breaker", { providerId, appType });
},
// 获取熔断器配置
async getCircuitBreakerConfig(): Promise<CircuitBreakerConfig> {
return invoke("get_circuit_breaker_config");
},
// 更新熔断器配置
async updateCircuitBreakerConfig(
config: CircuitBreakerConfig,
): Promise<void> {
return invoke("update_circuit_breaker_config", { config });
},
// 获取熔断器统计信息
async getCircuitBreakerStats(
providerId: string,
appType: string,
): Promise<CircuitBreakerStats | null> {
return invoke("get_circuit_breaker_stats", { providerId, appType });
},
};