'use client'; import { useState, useEffect } from 'react'; import { SettingsSection } from './SettingsSection'; import { Icons } from '@/components/ui/Icon'; import { userSourcesStore } from '@/lib/store/user-sources-store'; import type { VideoSource } from '@/lib/types'; export function UserSourceSettings() { const [sources, setSources] = useState([]); const [name, setName] = useState(''); const [baseUrl, setBaseUrl] = useState(''); const [error, setError] = useState(''); useEffect(() => { setSources(userSourcesStore.getSources()); const unsub = userSourcesStore.subscribe(() => { setSources(userSourcesStore.getSources()); }); return unsub; }, []); const handleAdd = (e: React.FormEvent) => { e.preventDefault(); if (!name.trim() || !baseUrl.trim()) { setError('名称和接口地址不能为空'); return; } try { new URL(baseUrl); } catch { setError('请输入有效的 URL'); return; } const id = `user-${name.toLowerCase().replace(/[^a-z0-9]/g, '-')}-${Date.now().toString(36)}`; const source: VideoSource = { id, name: name.trim(), baseUrl: baseUrl.trim(), searchPath: '/provide/vod', detailPath: '/provide/vod', enabled: true, }; userSourcesStore.addSource(source); setName(''); setBaseUrl(''); setError(''); }; return (
{/* Add form */}
{ setName(e.target.value); setError(''); }} className="flex-1 px-3 py-2 bg-[var(--glass-bg)] border border-[var(--glass-border)] rounded-[var(--radius-2xl)] text-sm text-[var(--text-color)] placeholder:text-[var(--text-color-secondary)]/50 focus:outline-none focus:border-[var(--accent-color)]" /> { setBaseUrl(e.target.value); setError(''); }} className="flex-[2] px-3 py-2 bg-[var(--glass-bg)] border border-[var(--glass-border)] rounded-[var(--radius-2xl)] text-sm text-[var(--text-color)] placeholder:text-[var(--text-color-secondary)]/50 focus:outline-none focus:border-[var(--accent-color)]" />
{error && (

{error}

)}
{/* Source list */} {sources.length > 0 && (
{sources.map(source => (

{source.name}

{source.baseUrl}

))}
)} {sources.length === 0 && (

还没有个人视频源,添加一个试试吧。

)}
); }