feat(identity): lazy TMDB lookup and bounded identity pool (DEC-1)
RSS/list releases that match no subscription or local work no longer hit
TMDB or open a pending item; they go to the identity pool as `unmatched`.
TMDB is queried only on a local alias hit, a published new-title rule whose
prefilter passes, manual/Agent retry, search results, or when the new
setting identity.eagerTmdbLookup (default off) is on. Mirrors MoviePilot:
torrents are recognised only when matched to a subscription or searched,
and recognition failures are logged, not alerted.
- Pending items only for related releases (ambiguous after lookup, or
related to a local work but unresolved); same source + normalized title
merge into one decision ("来源「X」的 N 条资源待识别"), resolve/dismiss
applies to the whole group, members detach as they get resolved.
- Pool governance: unmatched reviews capped (daily, 3x), title_alias
insert trigger wakes similar entries, stale unmatched entries archived
after identity.poolArchiveDays (30); review idempotency keys include the
due time.
- Migration 0047_identity_pool: reason/outcome `unmatched`,
identity_candidate.normalized_title (+trgm index), wake trigger, and
cleanup of open identity_unresolved items with no related work
(dismissed, resolution=moved_to_pool).
- Inbox: group by type + work/source with collapse, hide info-only items
by default (minSeverity=warning), badge counts warning+ only; pool sheet
gets manual TMDB/local-work assign and dismiss; settings card for the
new identity settings.
- Runbook docs/runbook/identity.md.
Requires rebuild/restart (migration runs on start).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
524af64bec
commit
94fd48bff2
24 files changed
+1326
-153
No files matched your search
@@ -12,6 +12,8 @@ import { useSse } from "~/lib/sse.ts";
|
||||
import { cn } from "~/lib/utils.ts";
|
||||
|
||||
// 顶栏收件箱(IA-3):待处理不进侧栏,铃铛 + 未决角标;下拉按问题类型列最近事项,点开进待处理页。
|
||||
// 角标只算需要你处理的事项(警告及以上):"仅信息"类(巡检报告、旧版本待处置等)不计入,在待处理页可展开查看。
|
||||
// 身份类事项已按来源 + 标题合并,一条事项可能代表多条资源(标题里写明 N 条)。
|
||||
|
||||
const RECENT = 8;
|
||||
const DOT = { info: "bg-muted-foreground/60", warning: "bg-warning", critical: "bg-destructive" } as const;
|
||||
@@ -27,7 +29,7 @@ export function useLiveDecisions() {
|
||||
void qc.invalidateQueries({ queryKey: decisionKeys.all });
|
||||
}, 800);
|
||||
});
|
||||
return useDecisionSummary();
|
||||
return useDecisionSummary(undefined, "warning");
|
||||
}
|
||||
|
||||
export const inboxPath = (kind?: string) => (kind ? `/console/inbox?kind=${kind}` : "/console/inbox");
|
||||
@@ -35,7 +37,7 @@ export const inboxPath = (kind?: string) => (kind ? `/console/inbox?kind=${kind}
|
||||
export function InboxBell() {
|
||||
const summary = useLiveDecisions();
|
||||
const [open, setOpen] = useState(false);
|
||||
const list = useDecisions({}, open);
|
||||
const list = useDecisions({ minSeverity: "warning" }, open);
|
||||
const navigate = useNavigate();
|
||||
const total = summary.data?.total ?? 0;
|
||||
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import type { IdentityPoolItem, PoolCandidate } from "@umt/contracts";
|
||||
import { ArrowRight, ExternalLink, LoaderCircle, RotateCw } from "lucide-react";
|
||||
import { ArrowRight, BellOff, ExternalLink, LoaderCircle, RotateCw } from "lucide-react";
|
||||
import { useId, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { toast } from "sonner";
|
||||
import { useRetryPool } from "~/api/identity.ts";
|
||||
import { useAssignPool, useDismissPool, useRetryPool } from "~/api/identity.ts";
|
||||
import { DetailSection, DetailSheet } from "~/components/console/detail-sheet.tsx";
|
||||
import { FormField } from "~/components/console/form-field.tsx";
|
||||
import { JsonView } from "~/components/console/json-view.tsx";
|
||||
import { KvList } from "~/components/console/kv-list.tsx";
|
||||
import { consolePath } from "~/components/console/nav.ts";
|
||||
import { EntityPicker, type PickedEntity } from "~/components/library/identity-entity-picker.tsx";
|
||||
import { Button } from "~/components/ui/button.tsx";
|
||||
import { Input } from "~/components/ui/input.tsx";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/components/ui/select.tsx";
|
||||
import { errorMessage } from "~/lib/api.ts";
|
||||
import { formatDateTime } from "~/lib/utils.ts";
|
||||
import { EVIDENCE_LEVEL, POOL_REASON, POOL_STATUS } from "./labels.ts";
|
||||
import { Chip, Tone } from "./parts.tsx";
|
||||
|
||||
// 待识别资源详情(只读):候选证据 + 重新识别。选候选、忽略在待处理里做(判定只在待处理与作品详情)。
|
||||
// 待识别资源详情:候选证据 + 重新识别 + 手动指定。进了待处理的(与订阅相关的歧义 / 无结果)在待处理里选候选;
|
||||
// 没进待处理的(unmatched:未命中订阅,惰性识别没查 TMDB)在这里手动指定 TMDB ID / 本地作品,或忽略。
|
||||
|
||||
/** 多个候选 / 待确认的资源开"待确认身份"事项;没有候选的(无结果、复查耗尽)开"待识别"事项 */
|
||||
/** 与订阅 / 本地作品相关的歧义开"待确认身份"事项,相关却无结果开"待识别"事项(同来源同标题合并);unmatched 不进待处理 */
|
||||
export function inInbox(item: Pick<IdentityPoolItem, "status" | "reason" | "candidates" | "decisionId">): boolean {
|
||||
return item.status === "pending" && (item.decisionId !== null || hasCandidates(item));
|
||||
}
|
||||
@@ -85,6 +91,97 @@ function CandidateRow({ c, index }: { c: PoolCandidate; index: number }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** 手动指定(复用 /identity-pool/{id}/assign,加人工锁)与忽略 */
|
||||
function ManualAssign({ item }: { item: IdentityPoolItem }) {
|
||||
const uid = useId();
|
||||
const assign = useAssignPool();
|
||||
const dismiss = useDismissPool();
|
||||
const [tmdbType, setTmdbType] = useState<"movie" | "tv">(item.query.season != null ? "tv" : "movie");
|
||||
const [tmdbId, setTmdbId] = useState("");
|
||||
const [entity, setEntity] = useState<PickedEntity | null>(null);
|
||||
const tmdbOk = /^\d{1,10}$/.test(tmdbId.trim());
|
||||
const run = async (body: Parameters<typeof assign.mutateAsync>[0], ok: string) => {
|
||||
try {
|
||||
await assign.mutateAsync(body);
|
||||
toast.success(ok);
|
||||
} catch (err) {
|
||||
toast.error(errorMessage(err, "指定失败"));
|
||||
}
|
||||
};
|
||||
return (
|
||||
<DetailSection title="手动指定">
|
||||
<div className="grid gap-x-2 sm:grid-cols-[8rem_minmax(0,1fr)_auto] sm:items-end">
|
||||
<FormField label="类型" htmlFor={`${uid}-type`}>
|
||||
<Select value={tmdbType} onValueChange={(v) => setTmdbType(v as "movie" | "tv")}>
|
||||
<SelectTrigger id={`${uid}-type`} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="movie">电影</SelectItem>
|
||||
<SelectItem value="tv">剧集</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</FormField>
|
||||
<FormField label="TMDB ID" htmlFor={`${uid}-tmdb`} hint="纯数字,如 872585">
|
||||
<Input
|
||||
id={`${uid}-tmdb`}
|
||||
inputMode="numeric"
|
||||
value={tmdbId}
|
||||
onChange={(e) => setTmdbId(e.target.value)}
|
||||
aria-invalid={tmdbId.trim() !== "" && !tmdbOk}
|
||||
/>
|
||||
</FormField>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mb-4"
|
||||
disabled={!tmdbOk || assign.isPending}
|
||||
onClick={() =>
|
||||
run(
|
||||
{
|
||||
id: item.id,
|
||||
external: { provider: "tmdb", entityType: tmdbType, externalId: tmdbId.trim() },
|
||||
lock: true,
|
||||
},
|
||||
"已按 TMDB ID 指定",
|
||||
)
|
||||
}
|
||||
>
|
||||
指定
|
||||
</Button>
|
||||
</div>
|
||||
<div className="grid gap-x-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end">
|
||||
<FormField label="或选本地作品">
|
||||
<EntityPicker value={entity} onChange={setEntity} />
|
||||
</FormField>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mb-4"
|
||||
disabled={!entity || assign.isPending}
|
||||
onClick={() => entity && run({ id: item.id, mediaEntityId: entity.id, lock: true }, "已关联本地作品")}
|
||||
>
|
||||
关联
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={dismiss.isPending}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await dismiss.mutateAsync({ id: item.id });
|
||||
toast.success("已忽略");
|
||||
} catch (err) {
|
||||
toast.error(errorMessage(err, "操作失败"));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<BellOff />
|
||||
忽略此资源
|
||||
</Button>
|
||||
</DetailSection>
|
||||
);
|
||||
}
|
||||
|
||||
export function PoolSheet({ item, onClose }: { item: IdentityPoolItem | null; onClose: () => void }) {
|
||||
const retry = useRetryPool();
|
||||
if (!item) return null;
|
||||
@@ -144,6 +241,8 @@ export function PoolSheet({ item, onClose }: { item: IdentityPoolItem | null; on
|
||||
]}
|
||||
/>
|
||||
|
||||
{item.status !== "resolved" && !queued ? <ManualAssign item={item} /> : null}
|
||||
|
||||
<DetailSection title={`候选(${item.candidates.length})`}>
|
||||
{item.candidates.length ? (
|
||||
<ul className="space-y-2">
|
||||
@@ -152,7 +251,11 @@ export function PoolSheet({ item, onClose }: { item: IdentityPoolItem | null; on
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="text-caption text-muted-foreground">没有候选。有新证据时自动重试。</p>
|
||||
<p className="text-caption text-muted-foreground">
|
||||
{item.reason === "unmatched"
|
||||
? "没有命中订阅或本地作品,未查询 TMDB。点「重新识别」会查一次 TMDB;新增相近别名时自动重试。"
|
||||
: "没有候选。有新证据时自动重试。"}
|
||||
</p>
|
||||
)}
|
||||
</DetailSection>
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ export function PoolTab() {
|
||||
empty={{
|
||||
icon: SearchX,
|
||||
title: filtered ? "没有符合条件的待识别资源" : "没有待识别资源",
|
||||
description: "证据不足或冲突的资源会出现在这里,有新证据时自动重试。",
|
||||
description: "未命中订阅、证据不足或冲突的资源会出现在这里;新增相近别名时自动重试,也可手动指定。",
|
||||
}}
|
||||
hasMore={pool.hasNextPage}
|
||||
onLoadMore={() => pool.fetchNextPage()}
|
||||
|
||||
@@ -164,6 +164,7 @@ export const POOL_REASON: Record<IdentityCandidateReason, ToneLabel> = {
|
||||
no_match: { label: "没有匹配", tone: "neutral" },
|
||||
proposed: { label: "待确认", tone: "warning" },
|
||||
lookup_failed: { label: "查询失败", tone: "destructive" },
|
||||
unmatched: { label: "未命中订阅", tone: "neutral" },
|
||||
};
|
||||
|
||||
export const POOL_STATUS: Record<string, ToneLabel> = {
|
||||
|
||||
@@ -180,6 +180,39 @@ function ImageCacheStatus() {
|
||||
);
|
||||
}
|
||||
|
||||
// 身份识别(DEC-1 惰性识别,对照 MP:RSS / 列表资源只在匹配订阅或用户搜索时识别)
|
||||
const IDENTITY_CARD: CardSpec = {
|
||||
anchor: "identity",
|
||||
title: "资源识别",
|
||||
description:
|
||||
"缺省只在资源命中订阅或本地作品别名、新作品收录规则前置条件通过、你手动识别或搜索时查 TMDB;其余进待识别池,不进待处理。",
|
||||
fields: [
|
||||
{
|
||||
name: "identity.eagerTmdbLookup",
|
||||
label: "每条新资源都查 TMDB",
|
||||
kind: "switch",
|
||||
hint: "旧行为。每条资源约 1–2 次搜索 + 命中时 1 次详情(识别缓存命中为 0);每小时 100 条的 RSS 约每天 2400–7200 次请求,站点独有的短剧 / 综艺多半查不到",
|
||||
wide: true,
|
||||
},
|
||||
{
|
||||
name: "identity.poolArchiveDays",
|
||||
label: "待识别池归档(天)",
|
||||
kind: "number",
|
||||
hint: "未命中订阅的条目超过这么多天没有新证据就归档,仍可筛出并手动指定",
|
||||
},
|
||||
],
|
||||
fromSettings: (s) => ({
|
||||
"identity.eagerTmdbLookup": s.identity.eagerTmdbLookup,
|
||||
"identity.poolArchiveDays": n(s.identity.poolArchiveDays),
|
||||
}),
|
||||
toPatch: (v) => ({
|
||||
identity: {
|
||||
eagerTmdbLookup: v["identity.eagerTmdbLookup"] === true,
|
||||
poolArchiveDays: Number(v["identity.poolArchiveDays"]),
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export function MetadataSection() {
|
||||
return (
|
||||
<SettingsGate>
|
||||
@@ -187,6 +220,7 @@ export function MetadataSection() {
|
||||
<>
|
||||
<SettingsCard section="metadata" spec={TMDB_CARD} settings={s} />
|
||||
<SettingsCard section="metadata" spec={TMDB_CACHE_CARD} settings={s} />
|
||||
<SettingsCard section="metadata" spec={IDENTITY_CARD} settings={s} />
|
||||
<SettingsCard section="metadata" spec={IMAGES_CARD} settings={s} />
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user