mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-17 14:45:11 +08:00
refactor: centralize batch import templates and enable config file access in Vite
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
||||
import { FileCode, Download, Upload, Copy, Check, AlertTriangle } from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { useI18n } from '../i18n'
|
||||
import { getBatchImportTemplates } from '../utils/batchImportTemplates'
|
||||
|
||||
export default function BatchImport({ onRefresh, onMessage, authFetch }) {
|
||||
const { t } = useI18n()
|
||||
@@ -11,55 +12,7 @@ export default function BatchImport({ onRefresh, onMessage, authFetch }) {
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
const apiFetch = authFetch || fetch
|
||||
const templates = {
|
||||
full: {
|
||||
name: t('batchImport.templates.full.name'),
|
||||
desc: t('batchImport.templates.full.desc'),
|
||||
config: {
|
||||
keys: ["your-api-key-1", "your-api-key-2"],
|
||||
accounts: [
|
||||
{ email: "user1@example.com", password: "password1", token: "" },
|
||||
{ email: "user2@example.com", password: "password2", token: "" },
|
||||
{ mobile: "+8613800138001", password: "password3", token: "" }
|
||||
],
|
||||
claude_model_mapping: {
|
||||
fast: "deepseek-chat",
|
||||
slow: "deepseek-reasoner"
|
||||
}
|
||||
}
|
||||
},
|
||||
email_only: {
|
||||
name: t('batchImport.templates.emailOnly.name'),
|
||||
desc: t('batchImport.templates.emailOnly.desc'),
|
||||
config: {
|
||||
keys: ["your-api-key"],
|
||||
accounts: [
|
||||
{ email: "account1@example.com", password: "pass1", token: "" },
|
||||
{ email: "account2@example.com", password: "pass2", token: "" },
|
||||
{ email: "account3@example.com", password: "pass3", token: "" }
|
||||
]
|
||||
}
|
||||
},
|
||||
mobile_only: {
|
||||
name: t('batchImport.templates.mobileOnly.name'),
|
||||
desc: t('batchImport.templates.mobileOnly.desc'),
|
||||
config: {
|
||||
keys: ["your-api-key"],
|
||||
accounts: [
|
||||
{ mobile: "+8613800000001", password: "pass1", token: "" },
|
||||
{ mobile: "+8613800000002", password: "pass2", token: "" },
|
||||
{ mobile: "+8613800000003", password: "pass3", token: "" }
|
||||
]
|
||||
}
|
||||
},
|
||||
keys_only: {
|
||||
name: t('batchImport.templates.keysOnly.name'),
|
||||
desc: t('batchImport.templates.keysOnly.desc'),
|
||||
config: {
|
||||
keys: ["key-1", "key-2", "key-3"]
|
||||
}
|
||||
}
|
||||
}
|
||||
const templates = getBatchImportTemplates(t)
|
||||
|
||||
const handleImport = async () => {
|
||||
if (!jsonInput.trim()) {
|
||||
|
||||
@@ -321,7 +321,7 @@
|
||||
"templates": {
|
||||
"full": {
|
||||
"name": "Full configuration template",
|
||||
"desc": "Includes keys, accounts, and model mapping"
|
||||
"desc": "Loaded from config.example.json with keys, accounts, and defaults"
|
||||
},
|
||||
"emailOnly": {
|
||||
"name": "Email-only accounts",
|
||||
|
||||
@@ -321,7 +321,7 @@
|
||||
"templates": {
|
||||
"full": {
|
||||
"name": "全量配置模板",
|
||||
"desc": "包含密钥、账号及模型映射"
|
||||
"desc": "直接复用 config.example.json,包含密钥、账号和默认配置"
|
||||
},
|
||||
"emailOnly": {
|
||||
"name": "仅邮箱账号",
|
||||
|
||||
42
webui/src/utils/batchImportTemplates.js
Normal file
42
webui/src/utils/batchImportTemplates.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import exampleConfig from '../../../config.example.json'
|
||||
|
||||
export function getBatchImportTemplates(t) {
|
||||
return {
|
||||
full: {
|
||||
name: t('batchImport.templates.full.name'),
|
||||
desc: t('batchImport.templates.full.desc'),
|
||||
config: exampleConfig,
|
||||
},
|
||||
email_only: {
|
||||
name: t('batchImport.templates.emailOnly.name'),
|
||||
desc: t('batchImport.templates.emailOnly.desc'),
|
||||
config: {
|
||||
keys: ['your-api-key'],
|
||||
accounts: [
|
||||
{ email: 'account1@example.com', password: 'pass1', token: '' },
|
||||
{ email: 'account2@example.com', password: 'pass2', token: '' },
|
||||
{ email: 'account3@example.com', password: 'pass3', token: '' },
|
||||
],
|
||||
},
|
||||
},
|
||||
mobile_only: {
|
||||
name: t('batchImport.templates.mobileOnly.name'),
|
||||
desc: t('batchImport.templates.mobileOnly.desc'),
|
||||
config: {
|
||||
keys: ['your-api-key'],
|
||||
accounts: [
|
||||
{ mobile: '+8613800000001', password: 'pass1', token: '' },
|
||||
{ mobile: '+8613800000002', password: 'pass2', token: '' },
|
||||
{ mobile: '+8613800000003', password: 'pass3', token: '' },
|
||||
],
|
||||
},
|
||||
},
|
||||
keys_only: {
|
||||
name: t('batchImport.templates.keysOnly.name'),
|
||||
desc: t('batchImport.templates.keysOnly.desc'),
|
||||
config: {
|
||||
keys: ['key-1', 'key-2', 'key-3'],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user