mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 18:50:49 +08:00
feat(config): add secure API key generator in visual editor
This commit is contained in:
@@ -106,6 +106,13 @@ function ApiKeysCardEditor({
|
|||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
const [formError, setFormError] = useState('');
|
const [formError, setFormError] = useState('');
|
||||||
|
|
||||||
|
function generateSecureApiKey(): string {
|
||||||
|
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
const array = new Uint8Array(17);
|
||||||
|
crypto.getRandomValues(array);
|
||||||
|
return 'sk-' + Array.from(array, (b) => charset[b % charset.length]).join('');
|
||||||
|
}
|
||||||
|
|
||||||
const openAddModal = () => {
|
const openAddModal = () => {
|
||||||
setEditingIndex(null);
|
setEditingIndex(null);
|
||||||
setInputValue('');
|
setInputValue('');
|
||||||
@@ -162,6 +169,11 @@ function ApiKeysCardEditor({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGenerate = () => {
|
||||||
|
setInputValue(generateSecureApiKey());
|
||||||
|
setFormError('');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-group" style={{ marginBottom: 0 }}>
|
<div className="form-group" style={{ marginBottom: 0 }}>
|
||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
|
||||||
@@ -233,6 +245,18 @@ function ApiKeysCardEditor({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
error={formError || undefined}
|
error={formError || undefined}
|
||||||
hint={t('config_management.visual.api_keys.input_hint')}
|
hint={t('config_management.visual.api_keys.input_hint')}
|
||||||
|
style={{ paddingRight: 148 }}
|
||||||
|
rightElement={
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleGenerate}
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
{t('config_management.visual.api_keys.generate')}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1011,6 +1011,7 @@
|
|||||||
"api_keys": {
|
"api_keys": {
|
||||||
"label": "API Keys List (api-keys)",
|
"label": "API Keys List (api-keys)",
|
||||||
"add": "Add API Key",
|
"add": "Add API Key",
|
||||||
|
"generate": "Generate",
|
||||||
"empty": "No API keys",
|
"empty": "No API keys",
|
||||||
"hint": "Each entry represents an API key (consistent with 'API Key Management' page style)",
|
"hint": "Each entry represents an API key (consistent with 'API Key Management' page style)",
|
||||||
"edit_title": "Edit API Key",
|
"edit_title": "Edit API Key",
|
||||||
|
|||||||
@@ -1016,6 +1016,7 @@
|
|||||||
"api_keys": {
|
"api_keys": {
|
||||||
"label": "Список API-ключей (api-keys)",
|
"label": "Список API-ключей (api-keys)",
|
||||||
"add": "Добавить API-ключ",
|
"add": "Добавить API-ключ",
|
||||||
|
"generate": "Сгенерировать",
|
||||||
"empty": "API-ключи отсутствуют",
|
"empty": "API-ключи отсутствуют",
|
||||||
"hint": "Каждая запись — это API-ключ (в том же стиле, что и на странице управления API-ключами)",
|
"hint": "Каждая запись — это API-ключ (в том же стиле, что и на странице управления API-ключами)",
|
||||||
"edit_title": "Редактирование API-ключа",
|
"edit_title": "Редактирование API-ключа",
|
||||||
|
|||||||
@@ -1011,6 +1011,7 @@
|
|||||||
"api_keys": {
|
"api_keys": {
|
||||||
"label": "API 密钥列表 (api-keys)",
|
"label": "API 密钥列表 (api-keys)",
|
||||||
"add": "添加 API 密钥",
|
"add": "添加 API 密钥",
|
||||||
|
"generate": "生成",
|
||||||
"empty": "暂无 API 密钥",
|
"empty": "暂无 API 密钥",
|
||||||
"hint": "每个条目代表一个 API 密钥(与 「API 密钥管理」 页面样式一致)",
|
"hint": "每个条目代表一个 API 密钥(与 「API 密钥管理」 页面样式一致)",
|
||||||
"edit_title": "编辑 API 密钥",
|
"edit_title": "编辑 API 密钥",
|
||||||
|
|||||||
Reference in New Issue
Block a user