Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/locales/en-US/apikeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default {
'apikeys.title.save': 'Save API Key',
'apikeys.form.expiretime': 'Expiration',
'apikeys.form.apikey': 'API Key',
'apikeys.form.keytype': 'Key Type',
'apikeys.form.keytype.auto': 'Auto-generated',
'apikeys.form.keytype.custom': 'Custom',
'apikeys.form.customkey': 'Custom API Key',
'apikeys.form.customkey.minlength': 'Custom API key must not be empty',
'apikeys.table.name': 'Key Name',
'apikeys.table.save.tips':
'Make sure to copy your key immediately. You will not be able to see it again.',
Expand Down
5 changes: 5 additions & 0 deletions src/locales/ja-JP/apikeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default {
'apikeys.title.save': 'APIキーを保存',
'apikeys.form.expiretime': '有効期限',
'apikeys.form.apikey': 'APIキー',
'apikeys.form.keytype': 'キーの種類',
'apikeys.form.keytype.auto': '自動生成',
'apikeys.form.keytype.custom': 'カスタム',
'apikeys.form.customkey': 'カスタムAPIキー',
'apikeys.form.customkey.minlength': 'カスタムAPIキーは空にできません',
'apikeys.table.name': 'キー名',
'apikeys.table.save.tips':
'キーをすぐにコピーしてください。一度閉じると再表示はできません。',
Expand Down
6 changes: 6 additions & 0 deletions src/locales/ru-RU/apikeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
'apikeys.title.save': 'Сохранить API-ключ',
'apikeys.form.expiretime': 'Срок действия',
'apikeys.form.apikey': 'API-ключ',
'apikeys.form.keytype': 'Тип ключа',
'apikeys.form.keytype.auto': 'Автоматически сгенерировано',
'apikeys.form.keytype.custom': 'Обычай',
'apikeys.form.customkey': 'Пользовательский ключ API',
'apikeys.form.customkey.minlength':
'Пользовательские API-ключи не могут быть пустыми.',
'apikeys.table.name': 'Название ключа',
'apikeys.table.save.tips':
'Обязательно скопируйте ключ сразу. Вы не сможете увидеть его снова.',
Expand Down
5 changes: 5 additions & 0 deletions src/locales/zh-CN/apikeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default {
'apikeys.title.save': '保存 API 密钥',
'apikeys.form.expiretime': '过期时间',
'apikeys.form.apikey': 'API 密钥',
'apikeys.form.keytype': '密钥类型',
'apikeys.form.keytype.auto': '自动生成',
'apikeys.form.keytype.custom': '自定义',
'apikeys.form.customkey': '自定义 API 密钥',
'apikeys.form.customkey.minlength': '自定义 API 密钥不能为空',
'apikeys.table.name': '密钥名称',
'apikeys.table.save.tips': '确保立即复制您的密钥。您将无法再次看到它!',
'apikeys.form.expiration.7days': '7天',
Expand Down
51 changes: 50 additions & 1 deletion src/pages/api-keys/components/add-apikey-modal/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SealSelect from '@/components/seal-form/seal-select';
import { PageAction } from '@/config';
import { PageActionType } from '@/config/types';
import { useIntl } from '@umijs/max';
import { Form } from 'antd';
import { Form, Radio } from 'antd';
import React from 'react';
import { expirationOptions } from '../../config';
import { FormData, ListItem } from '../../config/types';
Expand All @@ -15,6 +15,7 @@ const APIKeyForm: React.FC<{
onValuesChange?: (changedValues: any, allValues: any) => void;
}> = ({ action, currentData, onValuesChange }) => {
const intl = useIntl();
const [keyType, setKeyType] = React.useState<'auto' | 'custom'>('auto');

return (
<>
Expand All @@ -39,6 +40,54 @@ const APIKeyForm: React.FC<{
required
></SealInput.Input>
</Form.Item>

{/* Key type selection - only for create action */}
{action === PageAction.CREATE && (
<Form.Item label={intl.formatMessage({ id: 'apikeys.form.keytype' })}>
<Radio.Group
value={keyType}
onChange={(e) => setKeyType(e.target.value)}
>
<Radio value="auto">
{intl.formatMessage({ id: 'apikeys.form.keytype.auto' })}
</Radio>
<Radio value="custom">
{intl.formatMessage({ id: 'apikeys.form.keytype.custom' })}
</Radio>
</Radio.Group>
</Form.Item>
)}

{/* Custom API Key field - only shown when custom type is selected */}
{action === PageAction.CREATE && keyType === 'custom' && (
<Form.Item<FormData>
name="custom_key"
rules={[
{
required: true,
message: intl.formatMessage(
{ id: 'common.form.rule.input' },
{
name: intl.formatMessage({ id: 'apikeys.form.customkey' })
}
)
},
{
min: 1,
message: intl.formatMessage({
id: 'apikeys.form.customkey.minlength'
})
}
]}
>
<SealInput.Input
trim
label={intl.formatMessage({ id: 'apikeys.form.customkey' })}
required
></SealInput.Input>
</Form.Item>
)}

<Form.Item<FormData>
name="expires_in"
rules={[
Expand Down
1 change: 1 addition & 0 deletions src/pages/api-keys/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface FormData {
description: string;
allowed_model_names: string[];
expires_in: number | null;
custom_key?: string; // Optional custom API key
}