feat: v0.3.8–v0.3.14 工作区汇总(依赖升级、整理来源、手动入库、原地入库等)

生产 v0.3.8~v0.3.13 均由 8013196 加工作区修改构建部署,此前未提交;本提交补齐源码,
并含未部署的 v0.3.14 原地入库。中间各版本源码状态未保存,无法逐版拆分,详见
docs/plan/17-full-upgrade.md 与 docs/plan/18-organize-release.md。

- v0.3.8 全面升级:Deno workspace 依赖、Router 8 / Vite 8、camofox 1.18.0 / Node 24、
  PostgreSQL 18.6、备份客户端 18.6、演示 qB 5.2.4
- v0.3.9 媒体整理:分类规则、整理来源与目录快照(0059)、文件管理整理入口
- v0.3.10 手动下载与入库:独立手动下载、详情页资源下载、TMDB / Local 元数据兜底
  (metadata.resolve_organize)、正常多版本 / 一次性洗版(0060)
- v0.3.11 搜索详情与桌面黑边修复
- v0.3.12 列表分页、搜索历史、首页概况
- v0.3.13 统一整理弹窗与队列
- v0.3.14 原地入库(0061,未部署)

同批审计修复:
- 刮削入队:确认原记录存在后才删重放产生的新记录;写回 run 关联失败时保持 queued,
  由处理器补关联(对齐 MP 先登记、只在入队失败时记失败)
- 识别升级链只在结果更确定时采用,不再用 no_match 顶替原有歧义候选
- bluray_dir 资产以原盘目录本身为刮削根(MP 同做法)
- metadata.resolve_organize 登记到入库排障 Skill 与能力地图
- db/src/types.ts 按迁移重新生成;contracts 整理动作枚举顺序与数据库对齐
- 测试:原地入库用例改为直接查记录表;domain 测试模板补 version
- 前端:通知铃铛弹层与用户菜单统一样式;站点卡片共用卡头、底栏贴底、分页间距

依赖升级证据只提交摘要文件,registry-snapshot.json 移至 .local/(SHA-256 记于文档)。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-02 15:47:17 +08:00
1 parent 8013196e3f
commit ceb66f8c77
265 files changed
+17751 -2483

No files matched your search

@@ -11,8 +11,10 @@ import {
useRenamePasskey,
} from "~/api/auth.ts";
import { ConfirmDialog } from "~/components/console/confirm-dialog.tsx";
import { useListPagination } from "~/components/console/use-list-pagination.ts";
import { Button } from "~/components/ui/button.tsx";
import { Input } from "~/components/ui/input.tsx";
import { Pagination } from "~/components/ui/pagination.tsx";
import { errorMessage } from "~/lib/api.ts";
import { formatDateTime } from "~/lib/utils.ts";
import { SettingsBlock } from "./settings-block.tsx";
@@ -124,6 +126,7 @@ export function PasskeyBlock({ disabled }: { disabled: boolean }) {
const [name, setName] = useState("");
const supported = passkeySupported();
const items = list.data?.items ?? [];
const paged = useListPagination(items, { resetKey: String(disabled) });
const add = async (e: React.FormEvent) => {
e.preventDefault();
@@ -147,13 +150,14 @@ export function PasskeyBlock({ disabled }: { disabled: boolean }) {
<p className="text-caption text-muted-foreground">读取中…</p>
) : items.length ? (
<ul className="divide-y divide-border/60">
{items.map((p) => (
{paged.items?.map((p) => (
<PasskeyRow key={p.id} item={p} />
))}
</ul>
) : (
<p className="text-caption text-muted-foreground">还没有登记 Passkey。</p>
)}
{items.length > 0 ? <Pagination {...paged.pagination} /> : null}
{!supported ? (
<p className="text-meta text-muted-foreground">这个浏览器用不了 Passkey:需要 HTTPS 或 localhost 访问。</p>
) : adding ? (
@@ -1,5 +1,6 @@
import { LibraryRootsTable } from "./instances.tsx";
import { NamingSection } from "./naming.tsx";
import { ClassificationSection, OrganizeSourcesSection } from "./organize-sources.tsx";
import { str } from "./resource-section.tsx";
import { SettingsBlock } from "./settings-block.tsx";
import { type CardSpec, SettingsCard, SettingsGate } from "./settings-card.tsx";
@@ -98,6 +99,8 @@ export function LibrarySection() {
</SettingsBlock>
<SettingsGate>{(s) => <SettingsCard section="library" spec={ORGANIZE_CARD} settings={s} />}</SettingsGate>
<SettingsGate>{(s) => <SettingsCard section="library" spec={SCRAPE_CARD} settings={s} />}</SettingsGate>
<ClassificationSection />
<OrganizeSourcesSection />
<NamingSection />
</div>
);
@@ -0,0 +1,470 @@
import type { FileRef, OrganizeSourceInput, OrganizeSourceView } from "@umt/contracts";
import { cloneElement, type ReactElement, useId, useState } from "react";
import { toast } from "sonner";
import { filesErrorText, useFileRoots } from "~/api/files.ts";
import { downloaders } from "~/api/instances.ts";
import {
useClassification,
useOrganizeSources,
useOrganizeStock,
useRemoveOrganizeSource,
useSaveClassification,
useSaveOrganizeSource,
} from "~/api/organize-sources.ts";
import { openAgentDrawer } from "~/components/agent/agent-store.ts";
import { useListPagination } from "~/components/console/use-list-pagination.ts";
import { DirectoryDialog } from "~/components/files/directory-dialog.tsx";
import { stockWizardSource } from "~/components/organize/source-selection.tsx";
import { type OrganizeSource, OrganizeWizard } from "~/components/organize-wizard/organize-wizard.tsx";
import { Button } from "~/components/ui/button.tsx";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "~/components/ui/dialog.tsx";
import { Input } from "~/components/ui/input.tsx";
import { Pagination } from "~/components/ui/pagination.tsx";
import { Switch } from "~/components/ui/switch.tsx";
import { Textarea } from "~/components/ui/textarea.tsx";
import { formatDateTime } from "~/lib/utils.ts";
import { SaveBar, SettingsBlock } from "./settings-block.tsx";
const selectClass = "w-full rounded-lg border border-border bg-background px-3 py-2 text-caption";
function Field({ label, children }: { label: string; children: ReactElement<{ id?: string }> }) {
const id = useId();
return (
<label htmlFor={id} className="block space-y-1.5 text-caption">
<span>{label}</span>
{cloneElement(children, { id })}
</label>
);
}
export function ClassificationSection() {
const config = useClassification();
const save = useSaveClassification();
const [draft, setDraft] = useState<string | null>(null);
const yaml = draft ?? config.data?.yaml ?? "";
const dirty = draft !== null && draft !== config.data?.yaml;
return (
<SettingsBlock
section="library"
anchor="classification"
title="分类规则"
dirty={dirty}
description="电影使用 movie,剧集和综艺使用 tv;分类目录按下列规则生成。"
actions={
<Button
size="sm"
variant="outline"
onClick={() =>
openAgentDrawer({
label: "媒体分类规则",
goal: `协助检查和修改媒体分类 YAML,说明调整后的匹配结果。当前规则:\n${yaml}`,
})
}
>
让智能体协助
</Button>
}
>
{config.error ? (
<p role="alert" className="text-destructive">
{filesErrorText(config.error, "读取分类规则失败")}
</p>
) : null}
<Textarea
aria-label="分类规则 YAML"
className="min-h-80 font-mono text-caption"
value={yaml}
disabled={config.isPending || save.isPending}
onChange={(e) => setDraft(e.target.value)}
/>
<p className="mt-3 text-caption text-muted-foreground">
按书写顺序匹配,首个符合的分类生效。同一规则的多个字段为 AND;字段值用逗号表达 OR,用 ! 前缀排除。空规则(null
或 {"{}"})作为兜底,放在最后。
</p>
<p className="mt-2 text-caption text-muted-foreground">
可用字段:original_language(原始语言)、genre_ids(类型
ID)、production_countries(电影制作国家)、origin_country(剧集来源国家)、release_year(发行年份,支持
2020-2025 范围)。
</p>
<SaveBar dirty={dirty}>
<Button variant="outline" disabled={!dirty || save.isPending} onClick={() => setDraft(null)}>
撤销
</Button>
<Button
disabled={!dirty || !yaml.trim() || save.isPending}
onClick={() =>
save.mutate(yaml, {
onSuccess: () => {
setDraft(null);
toast.success("分类规则已保存");
},
onError: (e) => toast.error(filesErrorText(e, "保存分类规则失败")),
})
}
>
{save.isPending ? "保存中…" : "保存规则"}
</Button>
</SaveBar>
</SettingsBlock>
);
}
function SourceEditor({ initial, onClose }: { initial: OrganizeSourceView | null; onClose: () => void }) {
const [body, setBody] = useState<OrganizeSourceInput>(() =>
initial
? { ...initial }
: {
name: "",
enabled: true,
source: { root: "", path: "" },
target: { root: "", path: "" },
mediaType: "all",
category: null,
action: "copy",
trigger: "manual",
downloaderInstanceId: null,
tag: null,
intervalSec: 300,
},
);
const [picker, setPicker] = useState<"source" | "target" | null>(null);
const [id] = useState(() => initial?.id ?? crypto.randomUUID());
const roots = useFileRoots();
const instances = downloaders.useList();
const classification = useClassification();
const save = useSaveOrganizeSource();
const patch = (p: Partial<OrganizeSourceInput>) => setBody((b) => ({ ...b, ...p }));
const categories = [
...new Set(
body.mediaType === "all"
? [...(classification.data?.categories.movie ?? []), ...(classification.data?.categories.tv ?? [])]
: (classification.data?.categories[body.mediaType] ?? []),
),
];
const refLabel = (ref: FileRef) =>
ref.root
? `${roots.data?.find((r) => r.id === ref.root)?.name ?? ref.root} / ${ref.path || "(根目录)"}`
: "选择目录…";
const valid =
body.name.trim() &&
body.source.root &&
body.target.root &&
(body.trigger !== "qb_tag" || (body.downloaderInstanceId && body.tag?.trim())) &&
body.intervalSec >= 60 &&
body.intervalSec <= 86400;
return (
<>
<Dialog open onOpenChange={(open) => !open && !save.isPending && onClose()}>
<DialogContent className="max-h-[90vh] overflow-auto sm:max-w-2xl">
<DialogHeader>
<DialogTitle>{initial ? "编辑整理来源" : "新增整理来源"}</DialogTitle>
<DialogDescription>
首次保存或更换来源目录先建立当前文件基线,只自动处理后续新增文件。历史文件请使用「整理存量」。
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 sm:grid-cols-2">
<Field label="名称">
<Input value={body.name} onChange={(e) => patch({ name: e.target.value })} maxLength={100} />
</Field>
<Field label="启用">
<Switch aria-label="启用来源" checked={body.enabled} onCheckedChange={(enabled) => patch({ enabled })} />
</Field>
<Field label="来源目录">
<Button
variant="outline"
className="h-auto w-full justify-start whitespace-normal break-all text-left"
onClick={() => setPicker("source")}
>
{refLabel(body.source)}
</Button>
</Field>
<Field label="媒体库目标目录">
<Button
variant="outline"
className="h-auto w-full justify-start whitespace-normal break-all text-left"
onClick={() => setPicker("target")}
>
{refLabel(body.target)}
</Button>
</Field>
<Field label="媒体类型">
<select
className={selectClass}
value={body.mediaType}
onChange={(e) =>
patch({ mediaType: e.target.value as OrganizeSourceInput["mediaType"], category: null })
}
>
<option value="all">全部</option>
<option value="movie">电影</option>
<option value="tv">剧集 / 综艺</option>
</select>
</Field>
<Field label="分类">
<select
className={selectClass}
value={body.category ?? ""}
onChange={(e) => patch({ category: e.target.value || null })}
>
<option value="">自动匹配分类规则</option>
{body.category && !categories.includes(body.category) ? (
<option value={body.category}>{body.category}(当前配置)</option>
) : null}
{categories.map((c) => (
<option key={c}>{c}</option>
))}
</select>
</Field>
<Field label="整理方式">
<select
className={selectClass}
value={body.action}
onChange={(e) => patch({ action: e.target.value as "copy" | "move" })}
>
<option value="copy">复制,保留源文件</option>
<option value="move">移动,入库后删源</option>
</select>
</Field>
<Field label="触发方式">
<select
className={selectClass}
value={body.trigger}
onChange={(e) => patch({ trigger: e.target.value as OrganizeSourceInput["trigger"] })}
>
<option value="manual">手动</option>
<option value="qb_tag">qBittorrent 标签</option>
<option value="snapshot">目录快照监控</option>
</select>
</Field>
{body.trigger === "qb_tag" ? (
<>
<Field label="qBittorrent 实例">
<select
className={selectClass}
value={body.downloaderInstanceId ?? ""}
onChange={(e) => patch({ downloaderInstanceId: e.target.value || null })}
>
<option value="">选择实例…</option>
{instances.data?.items
.filter((d) => d.kind === "qbittorrent")
.map((d) => (
<option key={d.id} value={d.id}>
{d.name}
</option>
))}
</select>
</Field>
<Field label="标签">
<Input value={body.tag ?? ""} onChange={(e) => patch({ tag: e.target.value || null })} />
</Field>
</>
) : null}
{body.trigger === "snapshot" ? (
<Field label="扫描间隔(秒,60–86400)">
<Input
type="number"
min={60}
max={86400}
value={body.intervalSec}
onChange={(e) => patch({ intervalSec: Number(e.target.value) })}
/>
</Field>
) : null}
</div>
<p className="text-caption text-muted-foreground">
{body.category
? "固定分类:所选目标已是分类目录,不再追加分类层级。"
: "自动分类:在目标目录下追加规则匹配的分类目录。"}{" "}
同一个分类可配置多个不同来源。
</p>
<div className="flex justify-end gap-2">
<Button variant="outline" disabled={save.isPending} onClick={onClose}>
取消
</Button>
<Button
disabled={!valid || save.isPending}
onClick={() => {
const {
name,
enabled,
source,
target,
mediaType,
category,
action,
trigger,
downloaderInstanceId,
tag,
intervalSec,
} = body;
save.mutate(
{
id,
body: {
name,
enabled,
source,
target,
mediaType,
category,
action,
trigger,
downloaderInstanceId: trigger === "qb_tag" ? downloaderInstanceId : null,
tag: trigger === "qb_tag" ? tag : null,
intervalSec,
},
},
{
onSuccess: () => {
toast.success("来源已保存,当前存量不会自动整理");
onClose();
},
onError: (e) => toast.error(filesErrorText(e, "保存来源失败")),
},
);
}}
>
{save.isPending ? "保存并建立基线…" : "保存来源"}
</Button>
</div>
</DialogContent>
</Dialog>
{picker ? (
<DirectoryDialog
mode={picker}
value={body[picker]}
onClose={() => setPicker(null)}
onSelect={(ref) => {
patch({ [picker]: ref });
setPicker(null);
}}
/>
) : null}
</>
);
}
export function OrganizeSourcesSection() {
const roots = useFileRoots();
const pathLabel = (ref: FileRef) =>
`${roots.data?.find((r) => r.id === ref.root)?.name ?? "登记目录"} / ${ref.path || "(根目录)"}`;
const sources = useOrganizeSources();
const paged = useListPagination(sources.data?.items, { resetKey: "organize-sources" });
const save = useSaveOrganizeSource();
const remove = useRemoveOrganizeSource();
const stock = useOrganizeStock();
const [editor, setEditor] = useState<OrganizeSourceView | null | undefined>(undefined);
const [wizard, setWizard] = useState<OrganizeSource | null>(null);
const [deleting, setDeleting] = useState<OrganizeSourceView | null>(null);
return (
<SettingsBlock
section="library"
anchor="sources"
title="整理来源"
description="每条配置绑定一个来源与一个媒体库目标。新增来源建立基线,历史存量由你预览后执行。"
actions={
<Button size="sm" onClick={() => setEditor(null)}>
新增来源
</Button>
}
>
<div className="space-y-3">
{sources.isPending ? (
<p>读取来源中…</p>
) : sources.error ? (
<p role="alert" className="text-destructive">
{filesErrorText(sources.error, "读取来源失败")}
</p>
) : !sources.data?.items.length ? (
<p className="text-caption text-muted-foreground">尚未配置整理来源。</p>
) : (
paged.items?.map((p) => (
<div key={p.id} className="space-y-2 rounded-xl border border-border p-3">
<div className="flex flex-wrap items-center gap-2">
<strong className="mr-auto">{p.name}</strong>
<Switch
aria-label={`启用 ${p.name}`}
checked={p.enabled}
disabled={save.isPending}
onCheckedChange={(enabled) => {
const { id, baselineAt: _, lastScanAt: _s, lastError: _e, fileCount: _c, ...body } = p;
save.mutate(
{ id, body: { ...body, enabled } },
{ onError: (e) => toast.error(filesErrorText(e, "切换启用失败")) },
);
}}
/>
<Button size="sm" variant="outline" onClick={() => setEditor(p)}>
编辑
</Button>
<Button
size="sm"
variant="outline"
disabled={stock.isPending}
onClick={() =>
stock.mutate(
{ id: p.id },
{
onSuccess: (r) =>
r.items.length
? setWizard(stockWizardSource(p, r))
: toast.info(
`没有可整理文件;跳过 ${r.skipped},不可读取 ${r.unavailable}${r.truncated ? ",扫描达到上限" : ""}`,
),
onError: (e) => toast.error(filesErrorText(e, "扫描存量失败")),
},
)
}
>
整理存量
</Button>
<Button size="sm" variant="ghost" onClick={() => setDeleting(p)}>
删除
</Button>
</div>
<p className="break-all font-mono text-meta">
{pathLabel(p.source)} → {pathLabel(p.target)}
</p>
<p className="text-caption text-muted-foreground">
{p.action === "copy" ? "复制" : "移动"} ·{" "}
{p.mediaType === "movie" ? "电影" : p.mediaType === "tv" ? "剧集 / 综艺" : "全部类型"} ·{" "}
{p.category ?? "自动分类"} ·{" "}
{p.trigger === "snapshot"
? `目录快照 · 每 ${p.intervalSec} 秒`
: p.trigger === "qb_tag"
? `qBittorrent 标签 · ${p.tag}`
: "手动"}
</p>
<p className="text-meta text-muted-foreground">
基线:{p.baselineAt ? formatDateTime(p.baselineAt) : "尚未建立"} · 最近扫描:
{p.lastScanAt ? formatDateTime(p.lastScanAt) : "尚未扫描"} · 快照 {p.fileCount} 个文件
</p>
{p.lastError ? <p className="text-caption text-destructive">{p.lastError}</p> : null}
</div>
))
)}
</div>
{sources.data?.items.length ? <Pagination {...paged.pagination} /> : null}
{editor !== undefined ? <SourceEditor initial={editor} onClose={() => setEditor(undefined)} /> : null}
{wizard ? <OrganizeWizard source={wizard} onClose={() => setWizard(null)} /> : null}
{deleting ? (
<Dialog open onOpenChange={(o) => !o && setDeleting(null)}>
<DialogContent>
<DialogHeader>
<DialogTitle>删除来源「{deleting.name}」?</DialogTitle>
<DialogDescription>删除配置及监控快照,文件仍保留在原目录。</DialogDescription>
</DialogHeader>
<Button
variant="outline"
disabled={remove.isPending}
onClick={() =>
remove.mutate(deleting.id, {
onSuccess: () => setDeleting(null),
onError: (e) => toast.error(filesErrorText(e, "删除来源失败")),
})
}
>
确认删除来源
</Button>
</DialogContent>
</Dialog>
) : null}
</SettingsBlock>
);
}
@@ -7,7 +7,9 @@ import { ConfirmDialog } from "~/components/console/confirm-dialog.tsx";
import { DetailSection } from "~/components/console/detail-sheet.tsx";
import { zodFieldErrors } from "~/components/console/form-field.tsx";
import { StatusBadge } from "~/components/console/status-badge.tsx";
import { useListPagination } from "~/components/console/use-list-pagination.ts";
import { Button } from "~/components/ui/button.tsx";
import { Pagination } from "~/components/ui/pagination.tsx";
import { errorMessage } from "~/lib/api.ts";
import { healthLabel } from "~/lib/labels.ts";
import { FieldControl, type FormValues, num, str } from "./resource-section.tsx";
@@ -37,6 +39,7 @@ export function PathMappingsPanel({
const rows = (list.data?.items ?? []).filter((m) =>
viewKind === "downloader" ? m.downloaderInstanceId === instanceId : m.mediaServerInstanceId === instanceId,
);
const paged = useListPagination(rows, { resetKey: JSON.stringify({ viewKind, instanceId }) });
const rootOpts = [
{ value: "none", label: "不关联" },
...(roots.data?.items ?? []).map((d) => ({ value: d.id, label: d.name })),
@@ -96,7 +99,7 @@ export function PathMappingsPanel({
<p className="text-caption text-muted-foreground">还没有映射,路径两边一致时不用加。</p>
) : (
<ul className="divide-y divide-border/60 rounded-lg border border-border/60">
{rows.map((m) => {
{paged.items?.map((m) => {
const h = healthLabel(m.verifyStatus);
return (
<li key={m.id} className="flex items-center gap-2 px-3 py-2">
@@ -140,6 +143,7 @@ export function PathMappingsPanel({
})}
</ul>
)}
{rows.length > 0 ? <Pagination {...paged.pagination} /> : null}
{adding ? (
<form
onSubmit={submit}