Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(follow): 合集队列与另见徽章的出处改用站点图标,并与时间对齐

longmeidaob9541d727041
diff --git a/frontend/e2e/follow-source-icons.test.ts b/frontend/e2e/follow-source-icons.test.ts
new file mode 100644
index 000000000..763ee34cc
--- /dev/null
+++ b/frontend/e2e/follow-source-icons.test.ts
@@ -0,0 +1,138 @@
+/* 关注里「这一条出自哪个站」一律用站点图标表示,站名只落在图标的 alt/title 上。
+ *
+ * 守两处:详情下方视频合集的队列卡(出处图标、标记与时间同一行居中),以及卡片上的
+ * 「另见」徽章。演示库没有关注来源,这里按 `_group_payload`(`src/peach/web_follow.py`)
+ * 造一组跨站的同一条:主条目在 Fanbox,另两条在 Rule34.xxx。 */
+import assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+
+import type { Browser, Page } from 'playwright-core';
+
+import { launch, settle, visit, VIEWPORTS, type Visit } from './harness.ts';
+
+const DESKTOP = VIEWPORTS.find((viewport) => !viewport.mobile)!;
+
+/** 1×1 的透明 PNG:站点图标的请求有图可落,量的是它排出来的几何。 */
+const PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
+
+/** 一条可播的关注视频。字段以 `_item_payload` 为准。 */
+const followVideo = (id: number, provider: string, label: string, publishedAt: string) => ({
+ id, provider, provider_label: label, resource_provider: provider, source_id: 1,
+ source_label: `演示 · ${label}`, external_id: String(id), title: `演示视频 ${id}`,
+ author: null, summary: null, url: `https://example.com/${id}`, thumb_url: null,
+ published_at: publishedAt, published_precision: 'exact', version: null, duration: 20,
+ variant_kind: null, variant_label: null, status: 'new', asset_id: null,
+ media_needs_credential: false, media_error: null, has_media: true, media_kind: 'video',
+ width: null, height: null, playable: true, media_type: 'video/mp4', media_items: [],
+ hidden_media: [], resource_urls: [], tags: [], detail_tags: [], tag_types: {},
+});
+
+const GROUP = {
+ release_key: 'demo-release',
+ primary: followVideo(1, 'fanbox', 'pixivFANBOX', '2026-09-16T00:20:00Z'),
+ variants: [],
+ duplicates: [
+ followVideo(2, 'rule34xxx', 'Rule34.xxx', '2026-09-16T00:19:00Z'),
+ followVideo(3, 'rule34xxx', 'Rule34.xxx', '2026-09-16T00:16:00Z'),
+ ],
+ providers: ['fanbox', 'rule34xxx'],
+ has_wip: false,
+ is_release: false,
+ newest_at: '2026-09-16T00:20:00Z',
+ stack: null,
+};
+
+async function stubFollow(page: Page): Promise<void> {
+ const json = (body: unknown) => ({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
+ await page.route((url) => url.pathname === '/api/follow', (route) => route.fulfill(json({
+ groups: [GROUP], sources: [], counts: { new: 1, seen: 0, saved: 0, ignored: 0 },
+ facets: { authors: [], providers: ['fanbox', 'rule34xxx'] }, has_more: false,
+ })));
+ await page.route('**/api/follow/credentials', (route) => route.fulfill(json({ providers: [] })));
+ /* 服务端的定时检查可能正在跑,那一趟会让检查键挂着 aria-busy,settle 等不到头。 */
+ await page.route('**/api/follow/check', (route) => (route.request().method() === 'GET'
+ ? route.fulfill(json({ status: 'idle' })) : route.fallback()));
+ await page.route('**/source-icon**', (route) => route.fulfill({
+ status: 200, contentType: 'image/png', body: Buffer.from(PIXEL, 'base64'),
+ }));
+ // 造出来的条目没有正片;这一条量的是队列卡,播放器拿到空响应即可。
+ await page.route('**/follow-stream**', (route) => route.fulfill({ status: 204, body: '' }));
+ await page.route('**/follow-qualities**', (route) => route.fulfill(json({})));
+}
+
+async function openFollow(browser: Browser, path: string, ready: string): Promise<Visit> {
+ const opened = await visit(browser, path, DESKTOP);
+ await stubFollow(opened.page);
+ await opened.page.reload({ waitUntil: 'load' });
+ await opened.page.locator(ready).first().waitFor({ timeout: 15_000 });
+ await settle(opened.page);
+ return opened;
+}
+
+/** 一行里每个子盒的竖直中线与文字;站名文字是否混在行里看的是这一行自己的 textContent。 */
+async function lineGeometry(page: Page, selector: string) {
+ return page.locator(selector).evaluateAll((lines) => lines.map((line) => {
+ const mid = (node: Element | null) => {
+ if (!node) return null;
+ const box = node.getBoundingClientRect();
+ return box.top + box.height / 2;
+ };
+ const icon = line.querySelector('img');
+ return {
+ text: (line.textContent || '').trim(),
+ alt: icon?.getAttribute('alt') ?? null,
+ title: icon?.getAttribute('title') ?? null,
+ icon: mid(icon),
+ mark: mid(line.querySelector('.fvkind')),
+ time: mid(line.querySelector('time')),
+ line: mid(line),
+ };
+ }));
+}
+
+describe('关注的出处用站点图标', () => {
+ let browser: Browser;
+
+ before(async () => {
+ browser = await launch();
+ });
+
+ after(async () => {
+ await browser.close();
+ });
+
+ it('合集队列卡:出处是带站名的图标,与时间同一条中线', { timeout: 60_000 }, async () => {
+ const opened = await openFollow(browser, '/follow/item/1', '.followqueue .mixitem');
+ try {
+ const rows = await lineGeometry(opened.page, '.followqueue .mixitem .fqmeta');
+ assert.equal(rows.length, 3, `队列卡数不对:${JSON.stringify(rows)}`);
+ const duplicates = rows.filter((row) => row.alt !== null);
+ assert.equal(duplicates.length, 2, `另一站的两条没有出处图标:${JSON.stringify(rows)}`);
+ for (const row of duplicates) {
+ assert.equal(row.alt, 'Rule34.xxx', '出处图标没有站名作无障碍名称');
+ assert.equal(row.title, 'Rule34.xxx', '出处图标悬停不报站名');
+ assert.ok(!row.text.includes('Rule34'), `这一行还写着站名文字:${row.text}`);
+ assert.ok(Math.abs(row.icon! - row.time!) <= 1, `图标与时间中线差 ${Math.abs(row.icon! - row.time!)}px`);
+ }
+ // 本站那一条仍是标记加时间,二者同样按盒子居中。
+ const own = rows.find((row) => row.alt === null)!;
+ assert.ok(own.mark !== null && Math.abs(own.mark - own.time!) <= 1,
+ `标记与时间中线差 ${own.mark === null ? '未取得' : Math.abs(own.mark - own.time!)}px`);
+ } finally {
+ await opened.close();
+ }
+ });
+
+ it('卡片的「另见」徽章:另一站按图标列出,站名不写成文字', { timeout: 60_000 }, async () => {
+ const opened = await openFollow(browser, '/follow', '.followitem .fbadge.dup');
+ try {
+ const [badge] = await lineGeometry(opened.page, '.followitem .fbadge.dup');
+ assert.ok(badge, '卡片上没有「另见」徽章');
+ assert.equal(badge.text, '另见');
+ assert.equal(badge.alt, 'Rule34.xxx');
+ assert.ok(Math.abs(badge.icon! - badge.line!) <= 1, `图标偏离徽章中线 ${Math.abs(badge.icon! - badge.line!)}px`);
+ } finally {
+ await opened.close();
+ }
+ });
+});
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 01d3c81f5..c613cb2d2 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -3087,7 +3087,8 @@ class FollowWebSourceTests(unittest.TestCase):
self.assertIn(f"'{provider}'", icons)
self.assertNotIn("https://", icons)
self.assertPageContains(
- 'src="/source-icon?provider=${encodeURIComponent(provider)}" alt="" loading="lazy" data-drop="self"')
+ 'src="/source-icon?provider=${encodeURIComponent(provider)}" alt="${esc(label)}"'
+ '${label?` title="${esc(label)}"`:\'\'} loading="lazy" data-drop="self"')
# 取不到图标就把 <img> 摘掉,露出纯文字;收场动作由 image-fallback 的
# 委托监听执行,模板里只声明 `data-drop`。
self.assertPageContains('data-drop="self"')
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index c762c740d..184395f31 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -9149,7 +9149,8 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains('class="dupname" data-middle-truncate data-middle-truncate-within')
self.assertPageContains("if(element.dataset.middleTruncateWithin===undefined)return element.clientWidth;")
self.assertEqual(self.app_js.count('class="mixitemtext"'), 3)
- self.assertEqual(self.app_js.count("data-truncate-end"), 4)
+ # 关注合集队列卡的出处行是 flex 一行(`.fqmeta`),时间不收窄,不走尾部省略。
+ self.assertEqual(self.app_js.count("data-truncate-end"), 3)
self.assertPageContains("new Intl.Segmenter(undefined,{granularity:'grapheme'})")
self.assertPageContains("resizeObserver=new ResizeObserver")
self.assertPageContains("context.font=style.font||`${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`")
diff --git a/web/app.js b/web/app.js
index 17db6331a..e52d35fc7 100644
--- a/web/app.js
+++ b/web/app.js
@@ -5976,8 +5976,13 @@ function followBadges(group){
if(group.primary.variant_kind==='wip')badges.push('<span class="fbadge wip">WIP</span>');
else if(group.has_wip)badges.push('<span class="fbadge wip partial">含 WIP</span>');
if(group.primary.version)badges.push(`<span class="fbadge ver">${esc(group.primary.version)}</span>`);
- if(group.duplicates.length)badges.push(`<span class="fbadge dup">另见 ${
- esc([...new Set(group.duplicates.map(d=>d.provider_label))].join('、'))}</span>`);
+ /* 另见的站用站点图标列出,站名落在图标的 alt 与徽章的 title 上;没登记图标的站写站名。 */
+ if(group.duplicates.length){
+ const sites=new Map(group.duplicates.map(d=>[d.provider,d.provider_label||d.provider]));
+ const marks=[...sites].map(([provider,label])=>
+ sourceIcon(provider,label)||`<span>${esc(label)}</span>`).join('');
+ badges.push(`<span class="fbadge dup" title="另见 ${esc([...sites.values()].join('、'))}">另见 ${marks}</span>`);
+ }
return badges.join('');
}
@@ -6080,13 +6085,17 @@ function followQueueHtml(group,itemId){
const items=followVideoItems(group);
return `<aside class="mixqueue followqueue" data-queue-kind="collection"><div class="mixqueuehead"><div><h2>视频合集</h2><span>${esc(group.primary.title||'未命名合集')} · ${items.length} 个视频</span></div><div class="mixqueueactions">
<button data-follow-queue-close title="关闭" aria-label="关闭">${icon('x')}</button></div></div><div class="mixlist">${items.map(item=>{
- const copy=followCollectionCopy(group,item,group.duplicates.includes(item)?item.provider_label:'');
+ const duplicate=group.duplicates.includes(item);
+ const copy=followCollectionCopy(group,item,duplicate?item.provider_label:'');
+ // 另一站的同一条由站点图标报出处,图标的 alt 就是站名;没登记图标的站仍写站名。
+ const mark=duplicate&&sourceIcon(item.provider,item.provider_label)
+ ||`<i class="fvkind ${esc(item.variant_kind||'')}">${esc(copy.label)}</i>`;
const thumb=item.thumb_url
?`<img src="${esc(item.thumb_url)}" alt="" loading="lazy" referrerpolicy="no-referrer" data-drop="self">`
:followQueueNoThumb('video');
return `<div class="mixrow"><button class="mixitem ${item.id===itemId?'current':''}" data-follow-queue-item="${item.id}" aria-current="${item.id===itemId?'true':'false'}">
<span class="mixitempic">${thumb}${realDuration(item.duration)?`<i class="dur mono">${fmtDur(item.duration)}</i>`:''}</span>
- <span class="mixitemtext"><b data-truncate-end>${esc(copy.title)}</b><span data-truncate-end><i class="fvkind ${esc(item.variant_kind||'')}">${esc(copy.label)}</i>${followWhen(item)}</span></span></button></div>`;
+ <span class="mixitemtext"><b data-truncate-end>${esc(copy.title)}</b><span class="fqmeta">${mark}<time datetime="${esc(item.published_at||'')}">${esc(followWhen(item))}</time></span></span></button></div>`;
}).join('')}</div></aside>`;
}
@@ -6892,11 +6901,12 @@ async function openFollow(push=true,renderForDetail=false){
}
/* 有站点图标的来源。图标由服务端按 follow_assets.SOURCE_ICON_URLS 取回、保存在本机,
- 页面只认这张名单:没登记的来源直接不出 <img>,取不到的由 data-drop 摘掉退回纯文字。 */
+ 页面只认这张名单:没登记的来源直接不出 <img>,取不到的由 data-drop 摘掉退回纯文字。
+ 图标独自代表站名时传 label,alt 与 title 写站名;外层已经带名字的传空,图只作装饰。 */
const SOURCE_ICON_PROVIDERS=new Set(['fanbox','patreon','subscribestar','kemono','coomer','pawchive',
'rule34video','rule34xxx','rule34paheal','gofile','f95zone','simpcity']);
-function sourceIcon(provider){return SOURCE_ICON_PROVIDERS.has(provider)
- ? `<img class="ficon" src="/source-icon?provider=${encodeURIComponent(provider)}" alt="" loading="lazy" data-drop="self">`
+function sourceIcon(provider,label=''){return SOURCE_ICON_PROVIDERS.has(provider)
+ ? `<img class="ficon" src="/source-icon?provider=${encodeURIComponent(provider)}" alt="${esc(label)}"${label?` title="${esc(label)}"`:''} loading="lazy" data-drop="self">`
: ''}
function followAvatarInitial(group){
diff --git a/web/css/21-online.css b/web/css/21-online.css
index 4d64a0ff9..a182beed9 100644
--- a/web/css/21-online.css
+++ b/web/css/21-online.css
@@ -59,7 +59,7 @@
.fbadge.wip{border-color:var(--meter);color:var(--meter)}
/* 「含 WIP」说的是同组里还有一条半成品,这一条本身不是;配色要弱于 WIP 本体。 */
.fbadge.wip.partial{border-color:var(--border-15);color:var(--muted)}
-.fbadge.dup{border-style:dashed}
+.fbadge.dup{border-style:dashed;display:inline-flex;align-items:center;gap:4px}.fbadge.dup .ficon{margin:0}
.fnote{font-size:var(--fs-xs);color:var(--muted)}
.followitem .mixbadge{border:0;cursor:pointer;font:inherit}
.factions{position:absolute;right:10px;top:10px;z-index:7;display:flex;gap:6px;align-items:center;
@@ -79,6 +79,12 @@
.followdetailside .fstate{flex:none}
.fvkind{display:inline-block;max-width:120px;margin-right:6px;padding:1px 7px;border-radius:var(--badge-radius);overflow:hidden;text-overflow:ellipsis;vertical-align:-2px;background:var(--overlay-5);color:var(--muted);font-size:var(--fs-xs);font-style:normal}
.fvkind.wip{color:var(--meter)}.fvkind.alt{color:var(--ink-2)}
+/* 合集队列卡的出处与时间:标记、站点图标和时间按盒子居中成一行,不靠基线偏移去凑。
+ 标记可收窄(自带尾部省略),时间不收。 */
+.followqueue .fqmeta{display:flex;align-items:center;gap:6px}
+.followqueue .fqmeta .ficon{flex:none;margin:0}
+.followqueue .fqmeta .fvkind{flex:0 1 auto;min-width:0;margin:0}
+.followqueue .fqmeta time{flex:none;white-space:nowrap}
/* 媒体框不设视口高度的地板:里面的播放器高度由 16:9 和自己的宽度推出来,地板挂在 vh 上,
两个量朝相反方向走——414×913 的视口给出 566px 的框装 208px 的画面,上下各空 179px;
1280×900 的宽屏给出 558px 的框装 435px 的画面,多出的 123px 就是画面之外那层黑边。