Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 复用首页云下载封面并说明文件记录操作

longmeidaofe15da36b04c
diff --git a/docs/REUSE.md b/docs/REUSE.md
index ef8183918..7d5ca84db 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -738,6 +738,6 @@ Python 源文件纳入 `src/peach/library_sharing.py` 与 `src/peach/library_pro
云下载卡片的 `artwork` 只读取已入库任务绑定的本机资产,复用 `attach_artwork_fields`、`attach_card_performers`、`coverImage`、`ArtSlot` 与 `avatarInner`;封面沿用缩略图、版本和正封取景,女优头像沿用实体图片及姓名回退。页面轮询同步入库资料,提交与进度跟踪不等待图片,不额外创建取图任务或请求外部来源。没有封面时保留占位,图片失败使用共享回退处理。未新增依赖或 ledger 写入。
-桌面封面与右侧标题到按钮等高,取景复用 `coverAnchor` 并通过 `ResizeObserver` 同步实际容器比例;手机使用固定比例小封面。展开的完整标题位于卡片信息区下方,封面高度保持稳定。已入库且具有 `asset_id` 的任务,封面和标题使用原生链接打开 `/assets/:id`,同时保留新标签页与键盘访问;其他任务不提供详情链接。
+云下载封面复用首页 JAV 大图的 `COVER_FRONT_RATIO`、`data-media-pic` 容器、`coverAnchor` 正封裁切和同图模糊背景。桌面封面与右侧标题到按钮等高,`ResizeObserver` 按右侧内容高度和共享比例计算封面宽度;手机使用固定宽度的 3:4 小封面。展开的完整标题位于卡片信息区下方,封面高度保持稳定。已入库且具有 `asset_id` 的任务,封面和标题使用原生链接打开 `/assets/:id`,同时保留新标签页与键盘访问;其他任务不提供详情链接。
普通 Toast 与扫描任务卡共用 Agent Progress 外框,16px 半径由通知栈内的既有 token 解析,细边框与接触阴影分别复用 `border-button-default`、`elevation-xs`,不改变内容排版。浏览器回归核对桌面、手机和明暗主题下的外框一致性,并以同一任务、同一内容回放外框基线生成对比图。
diff --git a/frontend/e2e/design-activity.test.ts b/frontend/e2e/design-activity.test.ts
index 2b43eafdd..86b36e935 100644
--- a/frontend/e2e/design-activity.test.ts
+++ b/frontend/e2e/design-activity.test.ts
@@ -11,7 +11,8 @@ describe('任务页云下载布局', () => {
const title = '制作记录与采访合集:摄影、场景设计及幕后访谈 '.repeat(12);
const assetId = Number(requiredEnv('PEACH_E2E_ITEM'));
const opened = await visit(browser, '/tasks', viewport, async (page) => {
- await page.route('**/cover?*', (route) => route.fulfill({ contentType: 'image/png', body: Buffer.from(PIXEL, 'base64') }));
+ await page.route('**/cover?*', (route) => route.fulfill({ contentType: 'image/svg+xml',
+ body: '<svg xmlns="http://www.w3.org/2000/svg" width="1480" height="1000"><path fill="#666" d="M0 0h1480v1000H0z"/><path fill="#ddd" d="M776 0h704v1000H776z"/><path fill="#c44" d="M776 0h704v12H776zM776 988h704v12H776z"/></svg>' }));
await page.route('**/entity-image?*', (route) => route.fulfill({ contentType: 'image/png', body: Buffer.from(PIXEL, 'base64') }));
await page.route('**/api/downloads?*', (route) => route.fulfill({ json: {
available: false, providers: [], tasks: [{ id: 1, title, code: 'ABC-123', provider: '115',
@@ -19,6 +20,7 @@ describe('任务页云下载布局', () => {
postprocess_state: 'complete', postprocess_label: '整理完成', target: '/云下载',
source_uri: '', submitted_at: '2026-10-01T00:00:00Z', asset_id: assetId,
artwork: { id: 10, code: 'ABC-123', has_cover: true, cover_key: 'ABC-123',
+ poster_box: { x0: 776, y0: 0, x1: 1480, y1: 1000, px: [1480, 1000], method: 'fold' },
performer_entities: [{ id: 30, name: '测试女优', has_image: true }] } }],
} }));
});
@@ -50,6 +52,8 @@ describe('任务页云下载布局', () => {
const headingText = heading.querySelector('a')?.firstChild || heading.firstChild!;
code.setStart(headingText, 0);
code.setEnd(headingText, 'ABC-123'.length);
+ const pictureBox = picture.getBoundingClientRect();
+ const coverBox = cover.getBoundingClientRect();
return { title: heading.getBoundingClientRect().height,
line: Number.parseFloat(getComputedStyle(heading).lineHeight),
row: row.getBoundingClientRect().height, clipped: titleContent.scrollWidth > titleContent.clientWidth,
@@ -57,7 +61,12 @@ describe('任务页云下载布局', () => {
providerTop: provider.getBoundingClientRect().top, metadataTop: detail.getBoundingClientRect().top,
coverLeft: cover.getBoundingClientRect().left, textLeft: heading.getBoundingClientRect().left,
coverTop: cover.getBoundingClientRect().top, coverBottom: cover.getBoundingClientRect().bottom,
- coverHeight: cover.getBoundingClientRect().height,
+ coverHeight: coverBox.height, coverRatio: coverBox.width / coverBox.height,
+ panelLeft: pictureBox.left + pictureBox.width * 776 / 1480,
+ panelRight: pictureBox.right, panelTop: pictureBox.top, panelBottom: pictureBox.bottom,
+ coverRight: coverBox.right,
+ backdrop: getComputedStyle(cover, '::before').backgroundImage,
+ backdropFilter: getComputedStyle(cover, '::before').filter,
detailTop: detailColumn.getBoundingClientRect().top, detailBottom: detailColumn.getBoundingClientRect().bottom,
coverReady: picture.complete && picture.naturalWidth > 0, avatarReady: avatar.complete && avatar.naturalWidth > 0,
codeFits: code.getBoundingClientRect().width <= heading.clientWidth };
@@ -73,6 +82,12 @@ describe('任务页云下载布局', () => {
assert.equal(geometry.coverBottom, geometry.detailBottom);
}
assert.equal(geometry.coverReady, true);
+ assert.ok(Math.abs(geometry.coverRatio - .75) < .01, '封面框复用首页 JAV 大图比例');
+ assert.ok(geometry.panelLeft >= geometry.coverLeft - 1 && geometry.panelRight <= geometry.coverRight + 1
+ && geometry.panelTop >= geometry.coverTop - 1 && geometry.panelBottom <= geometry.coverBottom + 1,
+ `正封四边完整可见:${JSON.stringify(geometry)}`);
+ assert.notEqual(geometry.backdrop, 'none', '正封比例留白使用同图补底');
+ assert.ok(geometry.backdropFilter.includes('blur('), '补底复用首页模糊效果');
assert.equal(geometry.avatarReady, true);
assert.equal(await page.locator('[data-download-cover]').getByText('无封面').count(), 0);
assert.equal(geometry.providerTop, geometry.metadataTop, '来源文字与目录、时间没有对齐');
diff --git a/frontend/e2e/orphan-table.test.ts b/frontend/e2e/orphan-table.test.ts
index 0633e2d1c..3d3174bf6 100644
--- a/frontend/e2e/orphan-table.test.ts
+++ b/frontend/e2e/orphan-table.test.ts
@@ -61,7 +61,7 @@ describe('孤儿记录数据表', () => {
}
assert.equal(await section.locator('[data-data-table-panel] #orphan-records-title').count(), 1);
assert.equal(await table.locator('tbody tr').count(), 20);
- assert.equal(await section.getByRole('button', { name: '彻底删除所选(0)', exact: true }).count(), 0);
+ assert.equal(await section.getByRole('button', { name: '删除所选记录(0)', exact: true }).count(), 0);
const pagination = section.locator('[data-table-pagination]');
assert.ok((await pagination.textContent())?.includes('1–20 / 23 条作品'));
await pagination.getByRole('button', { name: /每页显示数量/ }).waitFor();
@@ -78,10 +78,10 @@ describe('孤儿记录数据表', () => {
assert.ok((await table.locator('tbody tr').first().textContent())?.includes('作品 1・'));
await pagination.scrollIntoViewIfNeeded();
await page.screenshot({ path: `../build/table-evidence/orphan-selected-${viewport.name}.png` });
- await section.getByRole('button', { name: '彻底删除所选(2)', exact: true }).click();
+ await section.getByRole('button', { name: '删除所选记录(2)', exact: true }).click();
await page.getByRole('dialog').getByRole('button', { name: '取消', exact: true }).click();
await table.locator('thead label:has(input[type="checkbox"])').click();
- await section.getByRole('button', { name: '彻底删除所选(23)', exact: true }).click();
+ await section.getByRole('button', { name: '删除所选记录(23)', exact: true }).click();
const dialog = page.getByRole('dialog');
const list = dialog.getByRole('list', { name: '所选记录', exact: true });
await list.waitFor();
diff --git a/frontend/src/react/activity/downloads-panel.tsx b/frontend/src/react/activity/downloads-panel.tsx
index 50dd27ccb..4dfbef0a9 100644
--- a/frontend/src/react/activity/downloads-panel.tsx
+++ b/frontend/src/react/activity/downloads-panel.tsx
@@ -27,6 +27,7 @@ import { SourceLabel } from '../components/source-label';
import { ArtSlot } from '../components/art-slot';
import { avatarInner, coverAnchor, coverImage, relayoutCovers } from '@peach/card-art';
import { entityPath } from '@peach/legacy/core';
+import { COVER_FRONT_RATIO } from '@peach/appearance';
export const DOWNLOADS_URL = '/api/downloads';
export const DOWNLOADS_KEY = ['downloads'] as const;
@@ -94,17 +95,18 @@ function TaskCard({ task, writable }: { task: DownloadTask; writable: boolean })
const cover = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
const box = cover.current;
- if (!box) return;
+ const details = box?.nextElementSibling;
+ if (!box || !details) return;
const frame = () => {
- const { width, height } = box.getBoundingClientRect();
- if (!width || !height) return;
- box.style.setProperty('--card-ratio', `${width} / ${height}`);
+ const { height } = details.getBoundingClientRect();
+ if (!height) return;
+ box.style.setProperty('--download-cover-width', `${height * COVER_FRONT_RATIO}px`);
box.querySelectorAll<HTMLImageElement>('img.cover').forEach((image) => {
if (image.complete && image.naturalWidth) coverAnchor(image);
});
};
const observer = new ResizeObserver(frame);
- observer.observe(box);
+ observer.observe(details);
frame();
return () => observer.disconnect();
}, []);
@@ -140,8 +142,9 @@ function TaskCard({ task, writable }: { task: DownloadTask; writable: boolean })
className: failed ? 'flex flex-col border-border-error-default' : 'flex flex-col',
})}>
<div className="flex items-start gap-3 px-5 pt-5 pb-4">
- <div ref={cover} data-download-cover="" style={{ '--card-ratio': '3 / 4' } as CSSProperties}
- className="relative flex aspect-3/4 w-20 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-background-tertiary-default text-caption-1-regular text-text-secondary sm:aspect-auto sm:w-24 sm:self-stretch">
+ <div ref={cover} data-download-cover="" data-media-pic=""
+ style={{ '--card-ratio': String(COVER_FRONT_RATIO), '--download-cover-width': '6rem' } as CSSProperties}
+ className="w-20 shrink-0 text-caption-1-regular text-text-secondary sm:w-(--download-cover-width) sm:self-stretch">
{!artwork?.has_cover ? <span>无封面</span> : null}
{artwork?.has_cover ? <ArtSlot artwork={{ kind: 'cover', html: coverImage(artwork, 'big') }}
relayout={(root) => relayoutCovers(root, 'big')} /> : null}
diff --git a/frontend/src/react/data-cleanup/orphan-records-card.tsx b/frontend/src/react/data-cleanup/orphan-records-card.tsx
index 4d785d497..4fc3807a6 100644
--- a/frontend/src/react/data-cleanup/orphan-records-card.tsx
+++ b/frontend/src/react/data-cleanup/orphan-records-card.tsx
@@ -31,23 +31,27 @@ function OrphanActions({ item, toast }: { item: OrphanRecord; toast(message: str
const [target, setTarget] = useState<number | null>(item.candidates[0]?.id ?? null);
const attach = useMutation({
mutationFn: () => attachOrphan(item.id, Number(target)),
- onSuccess: (data) => { toast(`记录已接到新文件,批次 ${data.batch}`); void refresh(); },
+ onSuccess: () => {
+ const destination = item.candidates.find((candidate) => candidate.id === target);
+ toast(`已将「${item.name}」的个人记录转移到「${destination?.name ?? '所选文件'}」`);
+ void refresh();
+ },
onError: (error) => toast(errorMessage(error)),
});
const purge = useMutation({
mutationFn: () => purgeOrphan(item.id),
onSuccess: (data) => {
toast(data.blocked.length
- ? `${item.name} 的文件又回到盘上,没有删除;下一次扫描会把它接回在库`
- : `已彻底删除 ${item.name}`);
+ ? `「${item.name}」的文件已恢复,记录未删除;下次扫描后恢复为在库状态`
+ : `已删除「${item.name}」的作品记录及个人记录`);
void refresh();
},
});
const remove = () => {
void confirmModal({
- title: '彻底删除',
- body: `将删除「${item.name}」这一条和它带的记录(${recordsText(item.records)})。此操作不可撤销。`,
- confirmLabel: '彻底删除',
+ title: '删除记录',
+ body: `将删除「${item.name}」的作品记录${recordsText(item.records) ? `及其个人记录(${recordsText(item.records)})` : ''}。此操作不可撤销。`,
+ confirmLabel: '删除记录',
danger: true,
onConfirm: () => purge.mutateAsync(),
});
@@ -56,7 +60,7 @@ function OrphanActions({ item, toast }: { item: OrphanRecord; toast(message: str
return (
<span className="flex min-w-48 flex-wrap items-center gap-2">
{item.candidates.length
- ? <Select aria-label={`把 ${item.name} 的记录接到哪个文件`} className="w-52" selectedKey={target}
+ ? <Select aria-label={`选择接收 ${item.name} 个人记录的文件`} className="w-52" selectedKey={target}
onSelectionChange={(key) => { if (key !== null) setTarget(Number(key)) }}>
{item.candidates.map((candidate) => (
<SelectItem key={candidate.id} id={candidate.id} textValue={candidateText(candidate)}>
@@ -64,12 +68,12 @@ function OrphanActions({ item, toast }: { item: OrphanRecord; toast(message: str
</SelectItem>
))}
</Select>
- : <span className="text-text-secondary">没有番号或文件名对得上的文件</span>}
+ : null}
{item.candidates.length
? <Button size="small" disabled={target === null} {...busyProps(busy)}
- onClick={() => attach.mutate()}>接到这个文件</Button>
+ onClick={() => attach.mutate()}>转移记录</Button>
: null}
- <Button variant="danger" size="small" {...busyProps(busy)} onClick={remove}>彻底删除</Button>
+ <Button variant="danger" size="small" {...busyProps(busy)} onClick={remove}>删除记录</Button>
</span>
);
}
@@ -104,22 +108,22 @@ export function OrphanRecordsCard({ toast }: { toast(message: string): void }) {
const purge = useMutation({
mutationFn: (ids: number[]) => purgeOrphan(ids),
onSuccess: (data) => {
- toast(`已彻底删除 ${data.purged} 条记录${data.blocked.length ? `,${data.blocked.length} 条文件已恢复,未删除` : ''}`);
+ toast(`已删除 ${data.purged} 条作品记录及其个人记录${data.blocked.length ? `;${data.blocked.length} 条文件已恢复,记录未删除` : ''}`);
setSelected([]); void refresh();
},
});
const removeSelected = (chosen: OrphanRecord[]) => void confirmModal({
- title: '彻底删除所选记录',
- body: `将删除以下 ${chosen.length} 条作品和它们带的全部记录。此操作不可撤销。`,
+ title: '删除所选记录',
+ body: `将删除以下 ${chosen.length} 条作品记录及其全部个人记录。此操作不可撤销。`,
items: chosen.map((item) => item.name),
- confirmLabel: '彻底删除所选记录', danger: true,
+ confirmLabel: '删除所选记录', danger: true,
onConfirm: () => purge.mutateAsync(chosen.map((item) => item.id)),
});
const columns: DataColumn<OrphanRecord>[] = [
{ id: 'item', label: '作品', value: (item) => item.name, render: (item) => <OrphanIdentity item={item} /> },
- { id: 'records', label: '带的记录', min: 144, value: (item) => recordsText(item.records),
- render: (item) => <span className="block min-w-28">{recordsText(item.records) || '无个人记录'}</span> },
- { id: 'target', label: '接到与操作', width: 360, min: 240, value: (item) => item.candidates.length,
+ { id: 'records', label: '个人记录', min: 144, value: (item) => recordsText(item.records),
+ render: (item) => <span className="block min-w-28">{recordsText(item.records) || '无'}</span> },
+ { id: 'target', label: '操作', width: 360, min: 240, value: (item) => item.candidates.length,
render: (item) => <OrphanActions item={item} toast={toast} /> },
];
if (!query.isError && !items.length) return null;
@@ -137,7 +141,7 @@ export function OrphanRecordsCard({ toast }: { toast(message: string): void }) {
selected={selected} onSelected={setSelected}
actions={(chosen) => <Button variant="danger" size="small" disabled={!chosen.length}
{...busyProps(purge.isPending)} onClick={() => removeSelected(chosen)}>
- {`彻底删除所选(${chosen.length})`}
+ {`删除所选记录(${chosen.length})`}
</Button>} />}
</section>
);
diff --git a/frontend/src/react/data-cleanup/resource-sync.ts b/frontend/src/react/data-cleanup/resource-sync.ts
index 60788f8ff..5ff25c1d9 100644
--- a/frontend/src/react/data-cleanup/resource-sync.ts
+++ b/frontend/src/react/data-cleanup/resource-sync.ts
@@ -119,7 +119,7 @@ export const purgeCount = (scan: ResourceScanState) =>
/** 标为已消失那一档的那一句;没有这一档时是空串。 */
const vanishText = (scan: ResourceScanState) => (scan.vanish
- ? `${count(scan.vanish)} 条作品记录的文件已丢失,个人记录保留,可在「文件已丢失的记录」中选择替代文件或彻底删除。`
+ ? `${count(scan.vanish)} 条作品记录的文件已丢失,个人记录保留,可在「文件已丢失的记录」中转移个人记录或删除记录。`
: '');
/** 不可撤销那一句:有标为已消失那一档时,只说删除的这几样。 */
diff --git a/frontend/test/react/data-cleanup.test.tsx b/frontend/test/react/data-cleanup.test.tsx
index 28164d790..bb811b3bb 100644
--- a/frontend/test/react/data-cleanup.test.tsx
+++ b/frontend/test/react/data-cleanup.test.tsx
@@ -287,7 +287,7 @@ describe('资源同步', () => {
await settle();
expect(seen[0]!.body).toBe(
'将永久删除文件已不在盘上的 3 条记录(含回收站里的)、3 个空文件夹,并清理 2 个闲置缓存。来源根目录保留。'
- + '这几样不可撤销。2 条作品记录的文件已丢失,个人记录保留,可在「文件已丢失的记录」中选择替代文件或彻底删除。');
+ + '这几样不可撤销。2 条作品记录的文件已丢失,个人记录保留,可在「文件已丢失的记录」中转移个人记录或删除记录。');
await settle();
expect(host.textContent).toContain(
'1 条作品记录已标为文件丢失,可在「文件已丢失的记录」中处理。1 条的记录已接到库里的另一个版本。');
@@ -478,7 +478,7 @@ describe('孤儿记录', () => {
expect(server.calls.map((call) => call.path)).toContain('/api/orphan-records');
});
- it('每条列出带的记录与候选文件;没有候选的只给彻底删除', async () => {
+ it('每条列出个人记录与候选文件;没有候选的只给删除记录', async () => {
serve({ '/api/orphan-records': orphans });
const host = await wrap(<OrphanRecordsCard toast={vi.fn()} />);
await settle();
@@ -488,37 +488,37 @@ describe('孤儿记录', () => {
expect(rows[0]!.textContent).toContain('ABC-123.mkv · 60 分钟');
expect(rows[0]!.querySelector('img')?.getAttribute('src')).toBe('/thumb?id=7&c=4');
expect(rows[1]!.textContent).toContain('稍后看 1 · 播放过');
- expect(rows[1]!.textContent).toContain('没有番号或文件名对得上的文件');
- expect(buttonNamed('接到这个文件', rows[1]!)).toBeFalsy();
- expect(buttonNamed('彻底删除', rows[1]!)).toBeTruthy();
+ expect(rows[1]!.querySelector('[role="combobox"]')).toBeNull();
+ expect(buttonNamed('转移记录', rows[1]!)).toBeFalsy();
+ expect(buttonNamed('删除记录', rows[1]!)).toBeTruthy();
});
- it('接到这个文件直接发,目标默认是时长最接近的那个', async () => {
+ it('转移记录直接发,目标默认是时长最接近的那个', async () => {
const server = serve({ '/api/orphan-records': orphans, '/api/orphan-records/attach': { ok: true, batch: 'user:reattach@1' } });
const toast = vi.fn();
const host = await wrap(<OrphanRecordsCard toast={toast} />);
await settle();
- await click(buttonNamed('接到这个文件', host));
+ await click(buttonNamed('转移记录', host));
await settle();
expect(server.posts('/api/orphan-records/attach')).toEqual([{ id: 7, target: 9 }]);
- expect(toast).toHaveBeenCalledWith('记录已接到新文件,批次 user:reattach@1');
+ expect(toast).toHaveBeenCalledWith('已将「ABC-123.mp4」的个人记录转移到「ABC-123.mkv」');
});
- /** 点第二条的「彻底删除」,交回弹层上写的与发出去的批量请求。 */
+ /** 点第二条的「删除记录」,交回弹层上写的与发出去的批量请求。 */
async function purgeSecond(answer: boolean) {
const seen = confirmWith(answer);
const server = serve({ '/api/orphan-records': orphans, '/api/batch': { ok: true, purged: 1, blocked: [] } });
const host = await wrap(<OrphanRecordsCard toast={vi.fn()} />);
await settle();
- await click(buttonNamed('彻底删除', host.querySelectorAll('[aria-label="文件已消失的作品"] tbody tr')[1]!));
+ await click(buttonNamed('删除记录', host.querySelectorAll('[aria-label="文件已消失的作品"] tbody tr')[1]!));
await settle();
return { seen, posts: server.posts('/api/batch') };
}
- it('彻底删除是危险确认,正文写明不可撤销,确认了才发批量删除', async () => {
+ it('删除记录需危险确认,正文写明不可撤销,确认了才发批量删除', async () => {
const { seen, posts } = await purgeSecond(true);
expect(seen[0]!.danger).toBe(true);
- expect(seen[0]!.body).toBe('将删除「海边.mp4」这一条和它带的记录(稍后看 1 · 播放过)。此操作不可撤销。');
+ expect(seen[0]!.body).toBe('将删除「海边.mp4」的作品记录及其个人记录(稍后看 1 · 播放过)。此操作不可撤销。');
expect(posts).toEqual([{ ids: [12], operation: 'delete' }]);
});
@@ -537,14 +537,14 @@ describe('孤儿记录', () => {
await click(buttonNamed('下一页', host));
await click(host.querySelector('input[aria-label="选择 作品 20"]'));
confirmWith(false);
- await click(buttonNamed('彻底删除所选(2)', host));
+ await click(buttonNamed('删除所选记录(2)', host));
expect(server.posts('/api/batch')).toEqual([]);
const seen = confirmWith(true);
- await click(buttonNamed('彻底删除所选(2)', host));
+ await click(buttonNamed('删除所选记录(2)', host));
await settle();
expect(seen[0]!.items).toEqual(['作品 0', '作品 20']);
expect(server.posts('/api/batch')).toEqual([{ ids: [30, 50], operation: 'delete' }]);
- expect(toast).toHaveBeenCalledWith('已彻底删除 1 条记录,1 条文件已恢复,未删除');
+ expect(toast).toHaveBeenCalledWith('已删除 1 条作品记录及其个人记录;1 条文件已恢复,记录未删除');
});
});