Files
UHD_Media_Tool/apps/web/app/routes/console/downloads.tsx
T
rootandClaude Opus 5.5 f8362a3f4c feat(web): site center page, add-site wizard, credentials, health and user-data chart (FE-2)
- 资源 → 站点:卡片 / 列表切换(URL ?view= + localStorage 记住),筛选全部 / 已启用 / 需处理,
  按分享率 / 上传 / 上次登录排序;卡片显示账号状态、凭证类型、上次登录、上传 / 下载 / 分享率、
  等级 / VIP、做种、健康检测结果与时间、快照、限流
- 操作:检测健康、刷新登录(wait:true 同步结果)、更新凭证、编辑(限流 / 快照 / 代理)、启停、
  删除(确认框列出影响)
- 添加站点向导:按适配器分组选 23 个定义(未实测标注)→ 名称 / 域名覆盖 / 凭证三选一
  (馒头默认 API Key)→ 保存并测试(刷新登录 + 健康检测);验证码 / 二次验证提示改用 Cookie
  并链接待处理
- 站点详情:概览(用户数据磁贴 + 30 天上传 / 下载与分享率折线,recharts,无彩)/ 资源 /
  快照与 Feed / 账号(凭证管理、Passkey、登录历史)
- 设置"站点与账号"改为"站点默认"(限流、快照周期、UA、代理、做种页数)
- 侧栏改名"站点";smoke 补站点路由;依赖新增 recharts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-28 16:08:29 +08:00

156 lines
5.5 KiB
TypeScript

import { useQueryClient } from "@tanstack/react-query";
import type { DownloadStatus, DownloadTask } from "@umt/contracts";
import { EventType } from "@umt/contracts";
import { Download, RefreshCw } from "lucide-react";
import { useState } from "react";
import { Link } from "react-router";
import { DOWNLOAD_STATUS_LABEL, useDownloaderNames, useDownloadTasks } from "~/api/downloads.ts";
import { type DataColumn, DataTable } from "~/components/console/data-table.tsx";
import { DetailSheet } from "~/components/console/detail-sheet.tsx";
import { FilterBar, FilterSelect } from "~/components/console/filter-bar.tsx";
import { consolePath } from "~/components/console/nav.ts";
import { PageHeader } from "~/components/console/page-header.tsx";
import { useQueryState } from "~/components/console/use-query-state.ts";
import { CacheVolumes } from "~/components/downloads/cache-volumes.tsx";
import {
DownloadDetail,
DownloadStatusBadges,
PauseResume,
ProgressLine,
} from "~/components/downloads/download-detail.tsx";
import { Button } from "~/components/ui/button.tsx";
import { relTime } from "~/components/workbench/release-fields.ts";
import { useSse } from "~/lib/sse.ts";
import { formatBytes } from "~/lib/utils.ts";
export const meta = () => [{ title: "下载队列 · UHD 媒体自动化控制台" }];
export default function DownloadsPage() {
const f = useQueryState(["status", "managed"] as const);
const [openId, setOpenId] = useState<string | null>(null);
const qc = useQueryClient();
const downloads = useDownloadTasks({
status: (f.values.status || undefined) as DownloadStatus | undefined,
managed: (f.values.managed || undefined) as "true" | "false" | undefined,
});
const names = useDownloaderNames();
// 下载进度/状态、阈值事件到达时刷新列表(SSE 为主,轮询兜底)
useSse(
[
EventType.downloadProgress,
EventType.downloadStatusChanged,
EventType.downloadSubmitted,
EventType.downloadThreshold,
],
() => void qc.invalidateQueries({ queryKey: ["downloads"] }),
);
const rows = downloads.data?.pages.flatMap((p) => p.items);
const open = rows?.find((t) => t.id === openId) ?? null;
const columns: DataColumn<DownloadTask>[] = [
{
key: "name",
header: "下载任务",
cell: (t) => (
<div className="min-w-0 max-w-sm">
<p className="line-clamp-2 break-all text-foreground">{t.name}</p>
<p className="mt-0.5 truncate text-meta text-muted-foreground">
{names.data?.get(t.instanceId) ?? "下载器"} · {t.tags.join(", ") || "无标签"}
</p>
</div>
),
},
{ key: "status", header: "状态", cell: (t) => <DownloadStatusBadges t={t} /> },
{ key: "progress", header: "进度", hideBelow: "sm", cell: (t) => <ProgressLine t={t} /> },
{
key: "size",
header: "大小",
hideBelow: "lg",
align: "right",
cell: (t) => (
<span className="whitespace-nowrap tabular-nums">
{t.sizeBytes === null ? "未知" : formatBytes(t.sizeBytes, 1)}
</span>
),
},
{
key: "at",
header: "更新",
hideBelow: "md",
cell: (t) => (
<span className="whitespace-nowrap text-muted-foreground">{relTime(t.lastSyncedAt ?? t.updatedAt)}</span>
),
},
{ key: "ops", header: "", align: "right", cell: (t) => <PauseResume t={t} size="xs" /> },
];
return (
<>
<PageHeader
title="下载队列"
description="阈值暂停不能手动绕过;无进展只记录,不自动换源。"
actions={
<Button variant="outline" size="sm" onClick={() => void qc.invalidateQueries({ queryKey: ["downloads"] })}>
<RefreshCw className={downloads.isFetching ? "animate-spin" : undefined} />
刷新
</Button>
}
/>
<CacheVolumes />
<FilterBar onReset={f.active ? f.reset : undefined}>
<FilterSelect
label="状态"
value={f.values.status}
onChange={(v) => f.set("status", v)}
options={Object.entries(DOWNLOAD_STATUS_LABEL).map(([value, label]) => ({ value, label }))}
/>
<FilterSelect
label="纳管"
value={f.values.managed}
onChange={(v) => f.set("managed", v)}
options={[
{ value: "true", label: "纳管任务" },
{ value: "false", label: "未纳管" },
]}
/>
</FilterBar>
<DataTable
columns={columns}
rows={rows}
rowKey={(t) => t.id}
loading={downloads.isPending}
error={downloads.error}
onRetry={() => void downloads.refetch()}
onRowClick={(t) => setOpenId(t.id)}
selectedKey={openId}
hasMore={downloads.hasNextPage}
onLoadMore={() => void downloads.fetchNextPage()}
loadingMore={downloads.isFetchingNextPage}
empty={{
icon: Download,
title: f.active ? "没有符合筛选的下载任务" : "还没有下载任务",
description: f.active ? undefined : "自动收录或在站点页下载后出现在这里。",
}}
/>
<DetailSheet
open={!!open}
onOpenChange={(o) => !o && setOpenId(null)}
width="lg"
title={open?.name ?? ""}
footer={
open ? (
<Button asChild variant="outline" size="sm">
<Link to={consolePath("downloads", open.id)}>打开详情页</Link>
</Button>
) : null
}
>
{open ? <DownloadDetail task={open} /> : null}
</DetailSheet>
</>
);
}