feat: 添加 API Key 锁定功能和请求头规则系统

1. API Key 锁定功能
- 管理员可锁定/解锁用户的 API Key
- 锁定后用户无法使用、修改或删除该 Key
- 前端显示锁定状态并禁用相关操作

2. 请求头规则系统
- 将 endpoint.headers 升级为 header_rules
- 支持 set(设置)、drop(删除)、rename(重命名)操作
- 前端提供可视化规则编辑界面
- 包含数据迁移脚本

Close #37 Close #86 Close #88
This commit is contained in:
fawney19
2026-01-16 01:18:54 +08:00
parent ea45918561
commit 8e11f3864a
22 changed files with 852 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
import client from '../client'
import type { ProviderEndpoint, ProxyConfig } from './types'
import type { ProviderEndpoint, ProxyConfig, HeaderRule } from './types'
/**
* 获取指定 Provider 的所有 Endpoints
@@ -27,7 +27,7 @@ export async function createEndpoint(
api_format: string
base_url: string
custom_path?: string
headers?: Record<string, string>
header_rules?: HeaderRule[]
timeout?: number
max_retries?: number
is_active?: boolean
@@ -47,7 +47,7 @@ export async function updateEndpoint(
data: Partial<{
base_url: string
custom_path: string | null
headers: Record<string, string>
header_rules: HeaderRule[]
timeout: number
max_retries: number
is_active: boolean

View File

@@ -62,6 +62,31 @@ export interface ProxyConfig {
enabled?: boolean // 是否启用代理false 时保留配置但不使用)
}
/**
* 请求头规则类型
* - set: 设置/覆盖请求头
* - drop: 删除请求头
* - rename: 重命名请求头(保留原值)
*/
export interface HeaderRuleSet {
action: 'set'
key: string
value: string
}
export interface HeaderRuleDrop {
action: 'drop'
key: string
}
export interface HeaderRuleRename {
action: 'rename'
from: string
to: string
}
export type HeaderRule = HeaderRuleSet | HeaderRuleDrop | HeaderRuleRename
export interface ProviderEndpoint {
id: string
provider_id: string
@@ -69,7 +94,8 @@ export interface ProviderEndpoint {
api_format: string
base_url: string
custom_path?: string // 自定义请求路径(可选,为空则使用 API 格式默认路径)
headers?: Record<string, string>
// 请求头配置
header_rules?: HeaderRule[] // 请求头规则列表,支持 set/drop/rename 操作
timeout: number
max_retries: number
is_active: boolean