2025-12-10 20:52:44 +08:00
|
|
|
import client from '../client'
|
|
|
|
|
import type { ProviderEndpoint } from './types'
|
|
|
|
|
|
2025-12-18 14:42:06 +08:00
|
|
|
/**
|
|
|
|
|
* 代理配置类型
|
|
|
|
|
*/
|
|
|
|
|
export interface ProxyConfig {
|
|
|
|
|
url: string
|
|
|
|
|
username?: string
|
|
|
|
|
password?: string
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-10 20:52:44 +08:00
|
|
|
/**
|
|
|
|
|
* 获取指定 Provider 的所有 Endpoints
|
|
|
|
|
*/
|
|
|
|
|
export async function getProviderEndpoints(providerId: string): Promise<ProviderEndpoint[]> {
|
|
|
|
|
const response = await client.get(`/api/admin/endpoints/providers/${providerId}/endpoints`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 Endpoint 详情
|
|
|
|
|
*/
|
|
|
|
|
export async function getEndpoint(endpointId: string): Promise<ProviderEndpoint> {
|
|
|
|
|
const response = await client.get(`/api/admin/endpoints/${endpointId}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 为 Provider 创建新的 Endpoint
|
|
|
|
|
*/
|
|
|
|
|
export async function createEndpoint(
|
|
|
|
|
providerId: string,
|
|
|
|
|
data: {
|
|
|
|
|
provider_id: string
|
|
|
|
|
api_format: string
|
|
|
|
|
base_url: string
|
|
|
|
|
custom_path?: string
|
|
|
|
|
auth_type?: string
|
|
|
|
|
auth_header?: string
|
|
|
|
|
headers?: Record<string, string>
|
|
|
|
|
timeout?: number
|
|
|
|
|
max_retries?: number
|
|
|
|
|
priority?: number
|
|
|
|
|
weight?: number
|
|
|
|
|
max_concurrent?: number
|
|
|
|
|
rate_limit?: number
|
|
|
|
|
is_active?: boolean
|
|
|
|
|
config?: Record<string, any>
|
2025-12-18 14:42:06 +08:00
|
|
|
proxy?: ProxyConfig
|
2025-12-10 20:52:44 +08:00
|
|
|
}
|
|
|
|
|
): Promise<ProviderEndpoint> {
|
|
|
|
|
const response = await client.post(`/api/admin/endpoints/providers/${providerId}/endpoints`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新 Endpoint
|
|
|
|
|
*/
|
|
|
|
|
export async function updateEndpoint(
|
|
|
|
|
endpointId: string,
|
|
|
|
|
data: Partial<{
|
|
|
|
|
base_url: string
|
|
|
|
|
custom_path: string
|
|
|
|
|
auth_type: string
|
|
|
|
|
auth_header: string
|
|
|
|
|
headers: Record<string, string>
|
|
|
|
|
timeout: number
|
|
|
|
|
max_retries: number
|
|
|
|
|
priority: number
|
|
|
|
|
weight: number
|
|
|
|
|
max_concurrent: number
|
|
|
|
|
rate_limit: number
|
|
|
|
|
is_active: boolean
|
|
|
|
|
config: Record<string, any>
|
2025-12-18 14:42:06 +08:00
|
|
|
proxy: ProxyConfig
|
2025-12-10 20:52:44 +08:00
|
|
|
}>
|
|
|
|
|
): Promise<ProviderEndpoint> {
|
|
|
|
|
const response = await client.put(`/api/admin/endpoints/${endpointId}`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除 Endpoint
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteEndpoint(endpointId: string): Promise<{ message: string; deleted_keys_count: number }> {
|
|
|
|
|
const response = await client.delete(`/api/admin/endpoints/${endpointId}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|