| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { Result } from '@/request/Result'
- import { get, post, del, put } from '@/request/index'
- import { type Ref } from 'vue'
- export interface ApiKey {
- id: string
- api_key_prefix: string
- name: string
- status: 'active' | 'disabled'
- last_used_at: string | null
- create_time: string
- }
- export interface CreateApiKeyResponse {
- id: string
- api_key: string
- api_key_prefix: string
- name: string
- status: string
- create_time: string
- }
- const api_key_prefix = '/platform/api-keys'
- /**
- * 获取 API Key 列表
- */
- const getApiKeyList: (loading?: Ref<boolean>) => Promise<Result<Array<ApiKey>>> = (loading) => {
- return get(api_key_prefix, undefined, loading)
- }
- /**
- * 创建 API Key(完整密钥仅返回一次)
- */
- const createApiKey: (
- data: { name?: string },
- loading?: Ref<boolean>,
- ) => Promise<Result<CreateApiKeyResponse>> = (data, loading) => {
- return post(api_key_prefix, data, loading)
- }
- /**
- * 更新 API Key 状态
- */
- const updateApiKeyStatus: (
- keyId: string,
- data: { status: string },
- loading?: Ref<boolean>,
- ) => Promise<Result<null>> = (keyId, data, loading) => {
- return put(`${api_key_prefix}/${keyId}`, data, loading)
- }
- /**
- * 删除 API Key
- */
- const deleteApiKey: (
- keyId: string,
- loading?: Ref<boolean>,
- ) => Promise<Result<null>> = (keyId, loading) => {
- return del(`${api_key_prefix}/${keyId}`, undefined, loading)
- }
- export { getApiKeyList, createApiKey, updateApiKeyStatus, deleteApiKey }
|