import React, { useEffect, useState } from 'react'; import { readYamlConfig, updateYamlConfig } from '../../utils/yamlHelper'; import { ConfigInput, ConfigSelect, ConfigToggle } from '../common/ConfigItem'; import TagSelector from "../TagSelector.jsx"; import Toast from "../toast.jsx"; // 定义配置项 const GENERIC_CONFIG = { basicInputs: [ { key: 'defaultPath', label: '视频保存路径', type: 'text', placeholder: '请输入视频保存路径...', defaultValue: './data/rcmp4/' }, { key: 'videoSizeLimit', label: '视频大小限制(MB)', type: 'number', hint: '超过限制转为群文件', defaultValue: 70 } ], proxyInputs: [ { key: 'proxyAddr', label: '魔法地址', type: 'text', placeholder: '请输入代理地址...', defaultValue: '127.0.0.1' }, { key: 'proxyPort', label: '魔法端口', type: 'text', placeholder: '请输入代理端口...', defaultValue: '7890' } ], streamInputs: [ { key: 'identifyPrefix', label: '识别前缀', type: 'text', placeholder: '请输入识别前缀...', defaultValue: '' }, { key: 'streamDuration', label: '视频最大时长(秒)', type: 'number', defaultValue: 10 } ], concurrencyInputs: [ { key: 'queueConcurrency', label: '队列并发数', type: 'number', hint: '仅影响B站下载', defaultValue: 1 }, { key: 'videoDownloadConcurrency', label: '视频下载并发数', type: 'number', defaultValue: 1 } ], textareas: [ { key: 'deeplApiUrls', label: 'DeepL API地址', placeholder: '请输入DeepL API地址,多个地址用逗号分隔...', defaultValue: '' } ], toggles: [ { key: 'streamCompatibility', label: '兼容模式', hint: 'NCQQ不用开启,其他ICQQ、LLO需要开启', defaultValue: false } ], otherInputs: [ { key: 'xiaohongshuCookie', label: '小红书Cookie', type: 'text', placeholder: '请输入小红书的Cookie...', defaultValue: '' }, { key: 'autoclearTrashtime', label: '自动清理时间', type: 'text', placeholder: '请输入Cron表达式...', hint: 'Cron表达式', defaultValue: '0 0 8 * * ?' } ], aiInputs: [ { key: 'aiBaseURL', label: 'AI接口地址', type: 'text', placeholder: '请输入AI接口地址...', defaultValue: '', hint: '用于识图的接口,kimi默认接口为:https://api.moonshot.cn,其他服务商自己填写' }, { key: 'aiApiKey', label: 'API Key', type: 'text', placeholder: '请输入API Key...', defaultValue: '', hint: '用于识图的api key,kimi接口申请:https://platform.moonshot.cn/console/api-keys' } ], aiSelects: [ { key: 'aiModel', label: 'AI模型', options: [ { value: 'moonshot-v1-8k', label: 'Moonshot V1 8K' }, { value: 'moonshot-v1-32k', label: 'Moonshot V1 32K' }, { value: 'moonshot-v1-128k', label: 'Moonshot V1 128K' }, // 可以根据需要添加更多模型选项 ], defaultValue: 'moonshot-v1-8k', hint: '模型,使用kimi不用填写,其他要填写' } ] }; // 生成默认配置 const DEFAULT_CONFIG = Object.values(GENERIC_CONFIG).reduce((acc, group) => { group.forEach(item => { acc[item.key] = item.defaultValue; }); return acc; }, {}); export default function Generic() { const [config, setConfig] = useState(DEFAULT_CONFIG); const [loading, setLoading] = useState(false); const [resolveOptions, setResolveOptions] = useState([]); const [selectedResolveTags, setSelectedResolveTags] = useState([]); useEffect(() => { const loadConfig = async () => { const yamlConfig = await readYamlConfig(); if (yamlConfig) { const newConfig = {}; Object.keys(DEFAULT_CONFIG).forEach(key => { newConfig[key] = yamlConfig[key] ?? DEFAULT_CONFIG[key]; }); setConfig(newConfig); } }; loadConfig(); }, []); useEffect(() => { // 获取解析控制器配置 const fetchResolveControl = async () => { try { const response = await fetch('/r/api/resolveControl'); const data = await response.json(); const enabledTags = data .filter(item => item.value === 1) .map(item => item.label); setSelectedResolveTags(enabledTags); setResolveOptions(data.map(item => item.label)); } catch (error) { console.error('获取解析控制器配置失败:', error); } }; fetchResolveControl(); }, []); const handleSave = async () => { setLoading(true); try { const success = await updateYamlConfig(config); if (success) { document.getElementById('generic-toast-success').classList.remove('hidden'); setTimeout(() => { document.getElementById('generic-toast-success').classList.add('hidden'); }, 3000); } } catch (error) { console.error('保存配置失败:', error); } finally { setLoading(false); } }; const handleConfigChange = (key, value) => { setConfig(prev => ({ ...prev, [key]: value })); }; const handleResolveTagsChange = async (tags) => { try { const response = await fetch('/r/api/resolveControl', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ selectedTags: tags }), }); if (response.ok) { setSelectedResolveTags(tags); } } catch (error) { console.error('更新解析控制器配置失败:', error); } }; // 渲染输入框组 const renderInputGroup = (inputs, title) => (
{inputs.map(item => (
handleConfigChange(item.key, value)} placeholder={item.placeholder} /> {item.hint && ( {item.hint} )}
))}
); return (

通用配置

基础配置

{/* 基础配置 */} {renderInputGroup(GENERIC_CONFIG.basicInputs)} {/* 解析控制 */}

全局解析控制

{/* 代理配置 */}

代理设置

{renderInputGroup(GENERIC_CONFIG.proxyInputs)} {/* 流媒体配置 */}

流媒体设置

{renderInputGroup(GENERIC_CONFIG.streamInputs)} {/* 并发配置 */}

并发设置

{renderInputGroup(GENERIC_CONFIG.concurrencyInputs)} {/* DeepL API配置 */}

API设置

{GENERIC_CONFIG.textareas.map(item => (