mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
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:
@@ -269,6 +269,7 @@ export interface AdminApiKey {
|
||||
name?: string
|
||||
key_display?: string // 脱敏后的密钥显示
|
||||
is_active: boolean
|
||||
is_locked: boolean // 管理员锁定标志
|
||||
is_standalone: boolean // 是否为独立余额Key
|
||||
balance_used_usd?: number // 已使用余额(仅独立Key)
|
||||
current_balance_usd?: number | null // 当前余额(独立Key预付费模式,null表示无限制)
|
||||
@@ -310,6 +311,12 @@ export interface ApiKeyToggleResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface ApiKeyLockResponse {
|
||||
id: string // UUID
|
||||
is_locked: boolean
|
||||
message: string
|
||||
}
|
||||
|
||||
// 管理员API密钥管理相关API
|
||||
export const adminApi = {
|
||||
// 获取所有独立余额Keys列表
|
||||
@@ -358,6 +365,14 @@ export const adminApi = {
|
||||
return response.data
|
||||
},
|
||||
|
||||
// 切换API密钥锁定状态(锁定/解锁)
|
||||
async toggleLockApiKey(keyId: string): Promise<ApiKeyLockResponse> {
|
||||
const response = await apiClient.patch<ApiKeyLockResponse>(
|
||||
`/api/admin/api-keys/${keyId}/lock`
|
||||
)
|
||||
return response.data
|
||||
},
|
||||
|
||||
// 为独立余额Key调整余额
|
||||
async addApiKeyBalance(keyId: string, amountUsd: number): Promise<AdminApiKey & { message: string }> {
|
||||
const response = await apiClient.patch<AdminApiKey & { message: string }>(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -120,6 +120,7 @@ export interface ApiKey {
|
||||
key?: string
|
||||
key_display: string
|
||||
is_active: boolean
|
||||
is_locked: boolean // 管理员锁定标志
|
||||
last_used_at?: string
|
||||
created_at: string
|
||||
total_requests?: number
|
||||
|
||||
@@ -48,6 +48,7 @@ export interface ApiKey {
|
||||
last_used_at?: string
|
||||
expires_at?: string // 过期时间
|
||||
is_active: boolean
|
||||
is_locked: boolean // 管理员锁定标志
|
||||
is_standalone: boolean // 是否为独立余额Key
|
||||
balance_used_usd?: number // 已使用余额(仅独立Key)
|
||||
current_balance_usd?: number | null // 当前余额(独立Key预付费模式,null表示无限制)
|
||||
|
||||
Reference in New Issue
Block a user