feat(web): W5-C subscription progress, manual search and episode total
- subscription sheet: 立即搜索, active-search times, 追更进度 (per-season total with source/lock, per-episode state chips, in-flight/deferred counts) and set/lock season episode total - labels for subscription pending and candidate decision deferred Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7aa6cac717
commit
80780add66
4 files changed
+175
-1
No files matched your search
@@ -1,10 +1,12 @@
|
||||
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
cursorPage,
|
||||
type EpisodeTotalSet,
|
||||
MediaEntity,
|
||||
Subscription,
|
||||
type SubscriptionCreate,
|
||||
type SubscriptionMediaKind,
|
||||
SubscriptionProgress,
|
||||
type SubscriptionStatus,
|
||||
type SubscriptionUpdate,
|
||||
} from "@umt/contracts";
|
||||
@@ -70,3 +72,31 @@ export function useEntityTitle(id: string | null | undefined) {
|
||||
queryFn: ({ signal }) => getParsed(MediaEntity, `/media-entities/${id}`, undefined, signal),
|
||||
});
|
||||
}
|
||||
|
||||
/** 订阅进度:季总集数账本 + 每集状态(已覆盖/在途/缺失/疑似缺集)+ Slot 在途与延后(W5-C) */
|
||||
export function useSubscriptionProgress(id: string | null | undefined, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ["subscriptions", "progress", id ?? ""],
|
||||
enabled: !!id && enabled,
|
||||
queryFn: ({ signal }) => getParsed(SubscriptionProgress, `/subscriptions/${id}/progress`, undefined, signal),
|
||||
});
|
||||
}
|
||||
|
||||
/** 手动主动搜索:按标题/别名在已开启站点搜索,结果走同一识别评估链 */
|
||||
export function useSearchSubscription() {
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.post<{ runId: string; deduplicated: boolean }>(`/subscriptions/${id}/search`),
|
||||
});
|
||||
}
|
||||
|
||||
/** 手动设置季总集数(不锁定时只升;锁定后元数据刷新不再改写) */
|
||||
export function useSetEpisodeTotal() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: EpisodeTotalSet & { id: string }) =>
|
||||
api
|
||||
.post<unknown>(`/subscriptions/${id}/episode-total`, body)
|
||||
.then((d) => parseOrThrow(SubscriptionProgress, d, "/subscriptions/episode-total")),
|
||||
onSuccess: (_d, v) => void qc.invalidateQueries({ queryKey: ["subscriptions", "progress", v.id] }),
|
||||
});
|
||||
}
|
||||
@@ -128,6 +128,7 @@ export const CANDIDATE_DECISION: Record<string, ToneLabel> = {
|
||||
reject: { label: "拒绝", tone: "destructive" },
|
||||
unknown_field: { label: "字段未知", tone: "warning" },
|
||||
skipped: { label: "跳过", tone: "neutral" },
|
||||
deferred: { label: "延后(单元在途)", tone: "warning" },
|
||||
};
|
||||
|
||||
export const DECISION_KIND: Record<DecisionKind, string> = {
|
||||
@@ -212,6 +213,7 @@ export const PRIORITY: Record<AcquisitionPriority, string> = {
|
||||
export const SUB_STATUS: Record<SubscriptionStatus, ToneLabel> = {
|
||||
active: { label: "进行中", tone: "success" },
|
||||
paused: { label: "已暂停", tone: "warning" },
|
||||
pending: { label: "待定(元数据未就绪)", tone: "warning" },
|
||||
completed: { label: "已完成", tone: "neutral" },
|
||||
cancelled: { label: "已取消", tone: "neutral" },
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@ const DECISION_LABEL = {
|
||||
reject: { label: "不收录", tone: "destructive" },
|
||||
unknown_field: { label: "缺字段,待复核", tone: "warning" },
|
||||
skipped: { label: "被跳过", tone: "neutral" },
|
||||
deferred: { label: "延后(单元在途)", tone: "warning" },
|
||||
} as const;
|
||||
|
||||
/** 本地库存 + 候选理由(来自作品详情:Slot / CandidateEvaluation),不从标题猜 */
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
SubscriptionCreate,
|
||||
SubscriptionMediaKind,
|
||||
SubscriptionMode,
|
||||
type SubscriptionProgress,
|
||||
type SubscriptionStatus,
|
||||
} from "@umt/contracts";
|
||||
import { CalendarClock, Check, FilePlus2, Pause, Play, Plus, Search, XCircle } from "lucide-react";
|
||||
@@ -17,6 +18,9 @@ import {
|
||||
type SubscriptionFilters,
|
||||
useCreateSubscription,
|
||||
useEntityTitle,
|
||||
useSearchSubscription,
|
||||
useSetEpisodeTotal,
|
||||
useSubscriptionProgress,
|
||||
useSubscriptions,
|
||||
useUpdateSubscription,
|
||||
} from "~/api/subscriptions.ts";
|
||||
@@ -248,6 +252,13 @@ function SubscriptionsTab() {
|
||||
|
||||
function SubscriptionSheet({ sub, onClose }: { sub: Subscription | null; onClose: () => void }) {
|
||||
const update = useUpdateSubscription();
|
||||
const search = useSearchSubscription();
|
||||
const runSearch = () =>
|
||||
sub &&
|
||||
search.mutate(sub.id, {
|
||||
onSuccess: () => toast.success("已开始在已开启站点搜索,结果会按收录目标自动评估"),
|
||||
onError: (e) => toast.error(errorMessage(e)),
|
||||
});
|
||||
const title = useEntityTitle(sub?.mediaEntityId);
|
||||
const setStatus = (status: SubscriptionStatus, done: string) =>
|
||||
sub
|
||||
@@ -270,7 +281,13 @@ function SubscriptionSheet({ sub, onClose }: { sub: Subscription | null; onClose
|
||||
footer={
|
||||
sub && sub.status !== "cancelled" && sub.status !== "completed" ? (
|
||||
<>
|
||||
{sub.status === "active" ? (
|
||||
{sub.mediaEntityId ? (
|
||||
<Button variant="outline" onClick={runSearch} disabled={search.isPending}>
|
||||
<Search />
|
||||
{search.isPending ? "搜索中…" : "立即搜索"}
|
||||
</Button>
|
||||
) : null}
|
||||
{sub.status === "active" || sub.status === "pending" ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setStatus("paused", "已暂停,不再发起新下载")}
|
||||
@@ -320,11 +337,22 @@ function SubscriptionSheet({ sub, onClose }: { sub: Subscription | null; onClose
|
||||
},
|
||||
{ label: "状态说明", value: sub.statusReason },
|
||||
{ label: "最近检查", value: formatDateTime(sub.lastCheckedAt) },
|
||||
{
|
||||
label: "主动搜索",
|
||||
value: sub.lastSearchedAt
|
||||
? `上次 ${formatDateTime(sub.lastSearchedAt)}${sub.nextSearchAt ? ` · 下次 ${formatDateTime(sub.nextSearchAt)}` : " · 周期搜索已关"}`
|
||||
: "尚未搜索",
|
||||
},
|
||||
{ label: "创建", value: `${formatDateTime(sub.createdAt)} · ${sub.createdBy ?? "—"}` },
|
||||
{ label: "策略版本", value: sub.policyRevisionId ?? "按当前已发布策略", mono: !!sub.policyRevisionId },
|
||||
]}
|
||||
/>
|
||||
</DetailSection>
|
||||
{sub.mediaEntityId && sub.mediaKind !== "movie" ? (
|
||||
<DetailSection title="追更进度">
|
||||
<ProgressPanel subId={sub.id} readOnly={sub.status === "cancelled"} />
|
||||
</DetailSection>
|
||||
) : null}
|
||||
<DetailSection title="追踪方式">
|
||||
<SubscriptionEditForm key={`${sub.id}-${sub.updatedAt}`} sub={sub} />
|
||||
</DetailSection>
|
||||
@@ -341,6 +369,119 @@ function SubscriptionSheet({ sub, onClose }: { sub: Subscription | null; onClose
|
||||
);
|
||||
}
|
||||
|
||||
const UNIT_STATE: Record<
|
||||
SubscriptionProgress["seasons"][number]["units"][number]["state"],
|
||||
{ label: string; cls: string }
|
||||
> = {
|
||||
covered: { label: "已入库", cls: "border-success/30 bg-success/10 text-foreground" },
|
||||
inflight: { label: "下载中", cls: "border-foreground/30 bg-foreground/[0.06] text-foreground" },
|
||||
missing: { label: "缺失", cls: "border-border text-muted-foreground" },
|
||||
suspected_missing: { label: "疑似缺集", cls: "border-warning/50 bg-warning/10 text-foreground" },
|
||||
out_of_range: { label: "不在范围", cls: "border-dashed border-border text-muted-foreground" },
|
||||
};
|
||||
|
||||
/** 每季总集数(来源/锁定)+ 每集状态;可手动设置总集数(不锁定只升) */
|
||||
function ProgressPanel({ subId, readOnly }: { subId: string; readOnly: boolean }) {
|
||||
const id = useId();
|
||||
const progress = useSubscriptionProgress(subId);
|
||||
const setTotal = useSetEpisodeTotal();
|
||||
const [season, setSeason] = useState("1");
|
||||
const [total, setTotalValue] = useState("");
|
||||
const [locked, setLocked] = useState(false);
|
||||
if (progress.isPending) return <p className="text-caption text-muted-foreground">读取中…</p>;
|
||||
if (progress.isError) return <p className="text-caption text-destructive">{errorMessage(progress.error)}</p>;
|
||||
const p = progress.data;
|
||||
const save = () =>
|
||||
setTotal.mutate(
|
||||
{ id: subId, seasonNumber: Number(season), total: Number(total), locked },
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.success(locked ? "总集数已锁定" : "总集数已更新(只升)");
|
||||
setTotalValue("");
|
||||
},
|
||||
onError: (e) => toast.error(errorMessage(e)),
|
||||
},
|
||||
);
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{!p.completable ? (
|
||||
<p className="text-meta text-muted-foreground">总集数未知或元数据未就绪:继续追踪,不会自动结束。</p>
|
||||
) : null}
|
||||
{p.seasons.length === 0 ? <p className="text-caption text-muted-foreground">还没有季信息。</p> : null}
|
||||
{p.seasons.map((s) => (
|
||||
<div key={s.seasonNumber} className="space-y-1.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
第 {s.seasonNumber} 季 · {s.totalKnown ? `共 ${s.episodeTotal} 集` : "总集数未知"}
|
||||
<span className="text-meta text-muted-foreground">
|
||||
{s.totalSource ? `(${s.totalSource}${s.totalLocked ? ",已锁定" : ""})` : ""}
|
||||
{s.complete ? " · 已齐" : ""}
|
||||
</span>
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{s.units.map((u) => (
|
||||
<span
|
||||
key={u.episode}
|
||||
title={`E${u.episode} ${UNIT_STATE[u.state].label}${u.quality ? ` · ${u.quality.resolution ?? ""} ${u.quality.source ?? ""}${u.quality.pri !== null ? ` pri ${u.quality.pri}` : ""}` : ""}`}
|
||||
className={cn("rounded-md border px-1.5 py-0.5 font-mono text-meta", UNIT_STATE[u.state].cls)}
|
||||
>
|
||||
E{String(u.episode).padStart(2, "0")}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
{s.suspectedMissing.length ? (
|
||||
<p className="text-meta text-muted-foreground">
|
||||
疑似缺集:{s.suspectedMissing.map((e) => `E${e}`).join("、")}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
{p.slots.some((x) => x.inflightPlans.length > 1 || x.deferred > 0) ? (
|
||||
<ul className="space-y-0.5 text-meta text-muted-foreground">
|
||||
{p.slots.map((x) => (
|
||||
<li key={x.slotId}>
|
||||
{x.name}:在途 {x.inflightPlans.length} 个计划,延后 {x.deferred} 个发布
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
{readOnly ? null : (
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<FormField label="季" htmlFor={`${id}-s`}>
|
||||
<Input
|
||||
id={`${id}-s`}
|
||||
className="w-16"
|
||||
inputMode="numeric"
|
||||
value={season}
|
||||
onChange={(e) => setSeason(e.target.value)}
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label="总集数" htmlFor={`${id}-t`}>
|
||||
<Input
|
||||
id={`${id}-t`}
|
||||
className="w-20"
|
||||
inputMode="numeric"
|
||||
value={total}
|
||||
onChange={(e) => setTotalValue(e.target.value)}
|
||||
/>
|
||||
</FormField>
|
||||
<label className="flex h-9 items-center gap-1.5 text-sm text-foreground">
|
||||
<input type="checkbox" checked={locked} onChange={(e) => setLocked(e.target.checked)} />
|
||||
锁定
|
||||
</label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={save}
|
||||
disabled={setTotal.isPending || !/^\d+$/.test(total) || Number(total) < 1 || !/^\d+$/.test(season)}
|
||||
>
|
||||
设置总集数
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SubscriptionEditForm({ sub }: { sub: Subscription }) {
|
||||
const id = useId();
|
||||
const update = useUpdateSubscription();
|
||||
|
||||
Reference in new issue
Block a user