import { useState, useEffect } from 'react'; import { readYamlConfig, updateYamlConfig } from '../../utils/yamlHelper'; import Toast from "../toast.jsx"; export default function Generic() { const [config, setConfig] = useState({ defaultPath: './data/rcmp4/', videoSizeLimit: 70, proxyAddr: '127.0.0.1', proxyPort: '7890', identifyPrefix: '', streamDuration: 10, streamCompatibility: false, queueConcurrency: 1, videoDownloadConcurrency: 1, autoclearTrashtime: '0 0 8 * * ?', xiaohongshuCookie: '', deeplApiUrls: '' }); const [loading, setLoading] = useState(false); // 读取配置 useEffect(() => { const loadConfig = async () => { const yamlConfig = await readYamlConfig(); if (yamlConfig) { setConfig({ defaultPath: yamlConfig.defaultPath || './data/rcmp4/', videoSizeLimit: yamlConfig.videoSizeLimit || 70, proxyAddr: yamlConfig.proxyAddr || '127.0.0.1', proxyPort: yamlConfig.proxyPort || '7890', identifyPrefix: yamlConfig.identifyPrefix || '', streamDuration: yamlConfig.streamDuration || 10, streamCompatibility: yamlConfig.streamCompatibility ?? false, queueConcurrency: yamlConfig.queueConcurrency || 1, videoDownloadConcurrency: yamlConfig.videoDownloadConcurrency || 1, autoclearTrashtime: yamlConfig.autoclearTrashtime || '0 0 8 * * ?', xiaohongshuCookie: yamlConfig.xiaohongshuCookie || '', deeplApiUrls: yamlConfig.deeplApiUrls || '' }); } }; loadConfig(); }, []); // 保存配置 const handleSave = async () => { setLoading(true); try { const success = await updateYamlConfig({ defaultPath: config.defaultPath, videoSizeLimit: config.videoSizeLimit, proxyAddr: config.proxyAddr, proxyPort: config.proxyPort, identifyPrefix: config.identifyPrefix, streamDuration: config.streamDuration, streamCompatibility: config.streamCompatibility, queueConcurrency: config.queueConcurrency, videoDownloadConcurrency: config.videoDownloadConcurrency, autoclearTrashtime: config.autoclearTrashtime, xiaohongshuCookie: config.xiaohongshuCookie, deeplApiUrls: config.deeplApiUrls }); 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 handleReset = async () => { const yamlConfig = await readYamlConfig(); if (yamlConfig) { setConfig({ defaultPath: yamlConfig.defaultPath || './data/rcmp4/', videoSizeLimit: yamlConfig.videoSizeLimit || 70, proxyAddr: yamlConfig.proxyAddr || '127.0.0.1', proxyPort: yamlConfig.proxyPort || '7890', identifyPrefix: yamlConfig.identifyPrefix || '', streamDuration: yamlConfig.streamDuration || 10, streamCompatibility: yamlConfig.streamCompatibility ?? false, queueConcurrency: yamlConfig.queueConcurrency || 1, videoDownloadConcurrency: yamlConfig.videoDownloadConcurrency || 1, autoclearTrashtime: yamlConfig.autoclearTrashtime || '0 0 8 * * ?', xiaohongshuCookie: yamlConfig.xiaohongshuCookie || '', deeplApiUrls: yamlConfig.deeplApiUrls || '', }); } }; return (