生产 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]>
219 lines
7.9 KiB
TypeScript
219 lines
7.9 KiB
TypeScript
import { AliasKind, type TitleAlias } from "@umt/contracts";
|
|
import { ExternalLink, Lock, Plus, Trash2 } from "lucide-react";
|
|
import { type FormEvent, useEffect, useState } from "react";
|
|
import { Link } from "react-router";
|
|
import { toast } from "sonner";
|
|
import { z } from "zod";
|
|
import { useAliases, useCreateAlias, useDeleteAlias } from "~/api/identity.ts";
|
|
import { ConfirmDialog } from "~/components/console/confirm-dialog.tsx";
|
|
import { type DataColumn, DataTable } from "~/components/console/data-table.tsx";
|
|
import { FilterBar } from "~/components/console/filter-bar.tsx";
|
|
import { FormField, zodFieldErrors } from "~/components/console/form-field.tsx";
|
|
import { consolePath } from "~/components/console/nav.ts";
|
|
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 { Switch } from "~/components/ui/switch.tsx";
|
|
import { errorMessage } from "~/lib/api.ts";
|
|
import { EntityPicker, type PickedEntity } from "./identity-entity-picker.tsx";
|
|
import { METADATA_SOURCE } from "./labels.ts";
|
|
import { Chip, Panel } from "./parts.tsx";
|
|
|
|
// 别名管理:检索尽量广(原名/译名/简称/站点标题),确认关联仍严格;用户新增的别名 source=user
|
|
|
|
const ALIAS_KIND: Record<z.infer<typeof AliasKind>, string> = {
|
|
original: "原名",
|
|
translated: "译名",
|
|
short: "简称",
|
|
site_title: "站点标题",
|
|
romanized: "罗马字",
|
|
other: "其他",
|
|
};
|
|
|
|
const AliasForm = z.object({
|
|
alias: z.string().trim().min(1, "填写别名").max(200, "最多 200 字"),
|
|
kind: AliasKind,
|
|
language: z
|
|
.string()
|
|
.trim()
|
|
.max(16, "语言代码过长")
|
|
.regex(/^$|^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$/, "如 zh-CN、en"),
|
|
locked: z.boolean(),
|
|
});
|
|
|
|
function AddAlias({ entity }: { entity: PickedEntity }) {
|
|
const create = useCreateAlias();
|
|
const [f, setF] = useState({ alias: "", kind: "short" as z.infer<typeof AliasKind>, language: "", locked: true });
|
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
const submit = async (e: FormEvent) => {
|
|
e.preventDefault();
|
|
const r = AliasForm.safeParse(f);
|
|
if (!r.success) {
|
|
setErrors(zodFieldErrors(r.error.issues));
|
|
return;
|
|
}
|
|
setErrors({});
|
|
try {
|
|
await create.mutateAsync({
|
|
mediaEntityId: entity.id,
|
|
alias: r.data.alias,
|
|
kind: r.data.kind,
|
|
language: r.data.language || null,
|
|
locked: r.data.locked,
|
|
source: "user",
|
|
});
|
|
toast.success(`已为「${entity.title}」添加别名`);
|
|
setF((x) => ({ ...x, alias: "" }));
|
|
} catch (err) {
|
|
toast.error(errorMessage(err));
|
|
}
|
|
};
|
|
return (
|
|
<form
|
|
onSubmit={submit}
|
|
noValidate
|
|
className="grid gap-2 border-t border-border/60 pt-3 sm:grid-cols-[1fr_9rem_7rem_auto_auto] sm:items-start"
|
|
>
|
|
<FormField label="新别名" htmlFor="alias-new" error={errors.alias}>
|
|
<Input
|
|
id="alias-new"
|
|
value={f.alias}
|
|
aria-invalid={!!errors.alias}
|
|
onChange={(e) => setF((x) => ({ ...x, alias: e.target.value }))}
|
|
placeholder="如:沙丘 2"
|
|
/>
|
|
</FormField>
|
|
<FormField label="类型" htmlFor="alias-kind">
|
|
<Select value={f.kind} onValueChange={(v) => setF((x) => ({ ...x, kind: v as typeof f.kind }))}>
|
|
<SelectTrigger id="alias-kind" className="w-full">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent position="popper">
|
|
{(Object.keys(ALIAS_KIND) as (keyof typeof ALIAS_KIND)[]).map((k) => (
|
|
<SelectItem key={k} value={k}>
|
|
{ALIAS_KIND[k]}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</FormField>
|
|
<FormField label="语言" htmlFor="alias-lang" error={errors.language}>
|
|
<Input
|
|
id="alias-lang"
|
|
value={f.language}
|
|
aria-invalid={!!errors.language}
|
|
onChange={(e) => setF((x) => ({ ...x, language: e.target.value }))}
|
|
placeholder="zh-CN"
|
|
/>
|
|
</FormField>
|
|
<FormField label="锁定" htmlFor="alias-lock" hint="自动刷新不删">
|
|
<div className="flex h-9 items-center">
|
|
<Switch id="alias-lock" checked={f.locked} onCheckedChange={(v) => setF((x) => ({ ...x, locked: v }))} />
|
|
</div>
|
|
</FormField>
|
|
<Button type="submit" className="sm:mt-6" disabled={create.isPending}>
|
|
<Plus />
|
|
添加
|
|
</Button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function AliasesPanel() {
|
|
const [entity, setEntity] = useState<PickedEntity | null>(null);
|
|
const [q, setQ] = useState("");
|
|
const [dq, setDq] = useState("");
|
|
useEffect(() => {
|
|
const t = setTimeout(() => setDq(q.trim()), 250);
|
|
return () => clearTimeout(t);
|
|
}, [q]);
|
|
const list = useAliases({ mediaEntityId: entity?.id, q: dq || undefined });
|
|
const del = useDeleteAlias();
|
|
const rows = list.data?.pages.flatMap((p) => p.items);
|
|
|
|
const columns: DataColumn<TitleAlias>[] = [
|
|
{
|
|
key: "alias",
|
|
header: "别名",
|
|
cell: (a) => (
|
|
<span className="inline-flex items-center gap-1.5 break-all text-foreground">
|
|
{a.locked ? <Lock className="h-3 w-3 shrink-0 text-muted-foreground" aria-label="已锁定" /> : null}
|
|
{a.alias}
|
|
</span>
|
|
),
|
|
},
|
|
{ key: "kind", header: "类型", cell: (a) => <Chip>{ALIAS_KIND[a.kind]}</Chip> },
|
|
{ key: "lang", header: "语言", hideBelow: "md", cell: (a) => a.language ?? "—" },
|
|
{ key: "source", header: "来源", hideBelow: "sm", cell: (a) => METADATA_SOURCE[a.source] ?? a.source },
|
|
{
|
|
key: "entity",
|
|
header: "作品",
|
|
hideBelow: "md",
|
|
cell: (a) => (
|
|
<Link
|
|
to={consolePath("library", a.mediaEntityId)}
|
|
className="inline-flex min-w-0 items-center gap-1 text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
|
|
>
|
|
<span className="truncate">{a.mediaEntityTitle ?? "查看"}</span>
|
|
<ExternalLink className="h-3 w-3 shrink-0" />
|
|
</Link>
|
|
),
|
|
},
|
|
{
|
|
key: "act",
|
|
header: <span className="sr-only">操作</span>,
|
|
align: "right",
|
|
cell: (a) => (
|
|
<ConfirmDialog
|
|
trigger={
|
|
<Button variant="ghost" size="icon-sm" aria-label={`删除别名 ${a.alias}`}>
|
|
<Trash2 />
|
|
</Button>
|
|
}
|
|
title={`删除别名「${a.alias}」?`}
|
|
description="删除后不再用这个别名匹配作品,已确认的外部身份不受影响。"
|
|
confirmLabel="删除"
|
|
destructive
|
|
onConfirm={async () => {
|
|
try {
|
|
await del.mutateAsync(a.id);
|
|
toast.success("别名已删除");
|
|
} catch (err) {
|
|
toast.error(errorMessage(err));
|
|
throw err;
|
|
}
|
|
}}
|
|
/>
|
|
),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<Panel title="按作品管理" description="选中作品后可添加别名" bodyClassName="space-y-3">
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
<EntityPicker value={entity} onChange={setEntity} />
|
|
<FilterBar search={{ value: q, onChange: setQ, placeholder: "按别名关键字过滤" }} className="mb-0" />
|
|
</div>
|
|
{entity ? <AddAlias key={entity.id} entity={entity} /> : null}
|
|
</Panel>
|
|
<DataTable
|
|
paginationKey={JSON.stringify({ entity: entity?.id, q })}
|
|
columns={columns}
|
|
rows={rows}
|
|
rowKey={(a) => a.id}
|
|
loading={list.isPending}
|
|
error={list.error}
|
|
onRetry={() => list.refetch()}
|
|
empty={{
|
|
title: entity ? `「${entity.title}」还没有别名` : "没有匹配的别名",
|
|
description: "别名用于按原始标题、译名、简称匹配作品。",
|
|
}}
|
|
hasMore={list.hasNextPage}
|
|
onLoadMore={() => list.fetchNextPage()}
|
|
loadingMore={list.isFetchingNextPage}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|