mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
feat: delete apikey
This commit is contained in:
@@ -30,7 +30,9 @@ const TableIconName = {
|
||||
online: 'ic:baseline-check-circle',
|
||||
cancel: 'ic:baseline-cancel-schedule-send',
|
||||
refresh: 'ic:baseline-refresh',
|
||||
logs: 'hugeicons:google-doc'
|
||||
logs: 'hugeicons:google-doc',
|
||||
disable: 'ic:baseline-pause-circle',
|
||||
enable: 'ic:baseline-play-circle'
|
||||
}
|
||||
// 表格操作栏按钮,受权限控制
|
||||
const TableBtnWithPermission = ({
|
||||
|
||||
@@ -187,7 +187,7 @@ export function useFetch() {
|
||||
}
|
||||
|
||||
// 如果响应体为JSON且指定了转换键,则转换响应数据
|
||||
if (isJsonHttp(response.headers)) {
|
||||
if (options?.eoApiPrefix||isJsonHttp(response.headers)) {
|
||||
const data = await response.json()
|
||||
const newData = (await pluginEventHub.emit('httpResponse', { data, continue: true })) as Response
|
||||
return shouldTransformKeys ? (keysToCamel(newData, options.eoTransformKeys as string[]) as T) : data
|
||||
|
||||
@@ -18,9 +18,9 @@ import CustomEdge from './components/CustomEdge'
|
||||
import { KeyStatusNode } from './components/KeyStatusNode'
|
||||
import { ModelCardNode } from './components/ModelCardNode'
|
||||
import { ServiceCardNode } from './components/NodeComponents'
|
||||
import { ModelData } from './components/types'
|
||||
import { LAYOUT } from './constants'
|
||||
import './styles.css'
|
||||
import { ModelData } from './types'
|
||||
|
||||
interface ApiResponse {
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Handle, Position } from '@xyflow/react'
|
||||
import React from 'react'
|
||||
import { KeyData } from './types'
|
||||
import { KeyData } from '../types'
|
||||
|
||||
interface KeyStatusNodeData {
|
||||
id: string
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Icon } from '@iconify/react'
|
||||
import { Handle, Position } from '@xyflow/react'
|
||||
import { t } from 'i18next'
|
||||
import React from 'react'
|
||||
import { ModelStatus } from './types'
|
||||
import { ModelStatus } from '../types'
|
||||
|
||||
interface ModelCardData {
|
||||
title: string
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
export type ModelStatus = 'enable' | 'abnormal'|'disable'
|
||||
export type KeyStatus ='normal' | 'abnormal'|'disable'
|
||||
export type ModelStatus = 'enable' | 'abnormal'|'disabled'
|
||||
export type KeyStatus ='normal' | 'abnormal'|'disabled'
|
||||
|
||||
export interface KeyData {
|
||||
id: string
|
||||
@@ -2,7 +2,7 @@ import { $t } from '@common/locales'
|
||||
import { DatePicker, Form, Input, Modal, Switch } from 'antd'
|
||||
import dayjs from 'dayjs'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { APIKey } from '..'
|
||||
import { APIKey } from '../types'
|
||||
|
||||
interface ApiKeyModalProps {
|
||||
visible: boolean
|
||||
|
||||
@@ -9,17 +9,7 @@ import AIProviderSelect from '@core/components/AIProviderSelect'
|
||||
import { Divider, message, Space, Typography } from 'antd'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import ApiKeyModal from './components/ApiKeyModal'
|
||||
|
||||
export interface APIKey extends Record<string, unknown> {
|
||||
id: string
|
||||
name: string
|
||||
status: 'normal' | 'exceeded' | 'expired' | 'disabled' | 'error'
|
||||
use_token: number
|
||||
update_time: string
|
||||
expire_time: string
|
||||
can_delete: boolean
|
||||
priority: number
|
||||
}
|
||||
import { APIKey } from './types'
|
||||
|
||||
const KeySettings: React.FC = () => {
|
||||
const pageListRef = useRef<ActionType>(null)
|
||||
@@ -84,8 +74,59 @@ const KeySettings: React.FC = () => {
|
||||
setEditingKey(null)
|
||||
}
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
setApiKeys(apiKeys.filter((key) => key.id !== id))
|
||||
const handleDelete = async (id: string) => {
|
||||
try {
|
||||
const response = await fetchData<BasicResponse<any>>('ai/resource/key', {
|
||||
method: 'DELETE',
|
||||
eoParams: {
|
||||
provider: selectedProvider,
|
||||
id: id,
|
||||
branchID: 0
|
||||
},
|
||||
eoApiPrefix: 'http://uat.apikit.com:11204/mockApi/aoplatform/api/v1/'
|
||||
})
|
||||
|
||||
if (response.code === STATUS_CODE.SUCCESS) {
|
||||
message.success($t('删除成功'))
|
||||
pageListRef.current?.reload()
|
||||
} else {
|
||||
message.error(response.msg || RESPONSE_TIPS.error)
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(RESPONSE_TIPS.error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleStatus = async (id: string, currentStatus: string) => {
|
||||
try {
|
||||
const newStatus = currentStatus === 'normal' ? 'disable' : 'enable'
|
||||
const response = await fetchData<BasicResponse<any>>(`ai/resource/key/${newStatus}`, {
|
||||
method: 'PUT',
|
||||
eoParams: {
|
||||
provider: selectedProvider,
|
||||
id: id
|
||||
},
|
||||
eoApiPrefix: 'http://uat.apikit.com:11204/mockApi/aoplatform/api/v1/'
|
||||
})
|
||||
|
||||
if (response.code === STATUS_CODE.SUCCESS) {
|
||||
message.success(newStatus === 'disable' ? $t('停用成功') : $t('启用成功'))
|
||||
setApiKeys(
|
||||
apiKeys.map((key) =>
|
||||
key.id === id
|
||||
? ({
|
||||
...key,
|
||||
status: newStatus === 'disable' ? 'disabled' : 'normal'
|
||||
} as APIKey)
|
||||
: (key as APIKey)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
message.error(response.msg || RESPONSE_TIPS.error)
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(RESPONSE_TIPS.error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDragSortEnd = async (beforeIndex: number, afterIndex: number, newDataSource: APIKey[]) => {
|
||||
@@ -164,7 +205,7 @@ const KeySettings: React.FC = () => {
|
||||
{
|
||||
title: '',
|
||||
key: 'option',
|
||||
btnNums: 3,
|
||||
btnNums: 4,
|
||||
fixed: 'right',
|
||||
valueType: 'option',
|
||||
render: (_: React.ReactNode, entity: APIKey) => [
|
||||
@@ -175,7 +216,20 @@ const KeySettings: React.FC = () => {
|
||||
onClick={() => handleEdit(entity)}
|
||||
btnTitle={$t('编辑')}
|
||||
/>,
|
||||
<Divider type="vertical" className="mx-0" key="div3" />,
|
||||
<Divider type="vertical" className="mx-0" key="div1" />,
|
||||
entity.status !== 'expired' && entity.status !== 'error' && (
|
||||
<>
|
||||
<TableBtnWithPermission
|
||||
access="system.settings.ai_key_resource.manager"
|
||||
key="toggle"
|
||||
btnType={entity.status === 'normal' ? 'disable' : 'enable'}
|
||||
onClick={() => handleToggleStatus(entity.id, entity.status)}
|
||||
btnTitle={entity.status === 'normal' ? $t('停用') : $t('启用')}
|
||||
/>
|
||||
<Divider type="vertical" className="mx-0" key="div2" />
|
||||
</>
|
||||
),
|
||||
|
||||
<TableBtnWithPermission
|
||||
access="system.settings.ai_key_resource.manager"
|
||||
key="delete"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
export interface APIKey extends Record<string, unknown> {
|
||||
id: string
|
||||
name: string
|
||||
status: 'normal' | 'exceeded' | 'expired' | 'disabled' | 'error'
|
||||
use_token: number
|
||||
update_time: string
|
||||
expire_time: string
|
||||
can_delete: boolean
|
||||
priority: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user