import { FormEvent, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import toast from 'react-hot-toast' import { Download, ShieldCheck } from 'lucide-react' import { downloadsAPI } from '../api/downloads' import { useAuthStore } from '../stores/auth' import { confirmAction } from '../components/confirmAction' import type { DownloadTask, QBitTorrent } from '../types' import { DownloadTaskCard, toLiveCard, toTaskCard } from './DownloadTaskCard' export function DownloadsPage() { const role = useAuthStore((s) => s.user?.role) const [tasks, setTasks] = useState([]) const [torrents, setTorrents] = useState(null) const [url, setURL] = useState('') const [savePath, setSavePath] = useState('') const refresh = () => downloadsAPI.list().then((d) => { setTasks(d.tasks) setTorrents(d.torrents) }) useEffect(() => { void refresh().catch(() => undefined) const id = window.setInterval(() => void refresh().catch(() => undefined), 5_000) return () => window.clearInterval(id) }, []) const onAdd = async (e: FormEvent) => { e.preventDefault() try { await downloadsAPI.add(url, savePath) toast.success('已加入下载队列') setURL('') setSavePath('') await refresh() } catch (err: unknown) { const msg = (err as { response?: { data?: { error?: string } } })?.response?.data?.error ?? '提交失败' toast.error(msg) } } return (

下载管理

页面仅展示安全标题、海报和进度信息,不再暴露种子原始 URL 或私有 Token。

setURL(e.target.value)} /> setSavePath(e.target.value)} />

当前下载

每 5 秒自动刷新
{torrents === null && (
尚未连接到下载器 —{' '} {role === 'admin' ? ( <> 请到{' '} 下载器 {' '} 页面添加并测试连接。 ) : ( '请联系管理员添加并测试下载器连接。' )}
)} {torrents && torrents.length === 0 && (
暂无运行中任务。
)} {torrents && torrents.length > 0 && (
{torrents.map((torrent) => ( { if (!(await confirmAction({ title: '删除下载任务', message: `删除「${torrent.title || torrent.name}」?`, confirmText: '删除' }))) return await downloadsAPI.remove(torrent.hash, false) toast.success('已删除任务') await refresh() }} /> ))}
)}

下载历史

{tasks.length === 0 ? (
暂无历史下载。
) : (
{tasks.map((task) => ( ))}
)}
) }