Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 关注卡的「另见」相对卡面那一条列站点

longmeidao1380b2aa84de
diff --git a/frontend/e2e/follow-source-icons.test.ts b/frontend/e2e/follow-source-icons.test.ts
index 763ee34cc..659f69f19 100644
--- a/frontend/e2e/follow-source-icons.test.ts
+++ b/frontend/e2e/follow-source-icons.test.ts
@@ -42,11 +42,25 @@ const GROUP = {
stack: null,
};
+/** 主条目在 Fanbox 却没有视频:卡面换成组里最新那条 Rule34.xxx,另见就该列 Fanbox 与 Pawchive。 */
+const FRONTED = {
+ ...GROUP,
+ release_key: 'demo-fronted',
+ primary: { ...followVideo(11, 'fanbox', 'pixivFANBOX', '2026-09-15T00:20:00Z'),
+ has_media: false, media_kind: null, playable: false, duration: null },
+ duplicates: [
+ followVideo(12, 'rule34xxx', 'Rule34.xxx', '2026-09-15T00:19:00Z'),
+ followVideo(13, 'pawchive', 'Pawchive', '2026-09-15T00:16:00Z'),
+ ],
+ providers: ['fanbox', 'pawchive', 'rule34xxx'],
+ newest_at: '2026-09-15T00:20:00Z',
+};
+
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,
+ groups: [GROUP, FRONTED], sources: [], counts: { new: 2, seen: 0, saved: 0, ignored: 0 },
+ facets: { authors: [], providers: ['fanbox', 'pawchive', 'rule34xxx'] }, has_more: false,
})));
await page.route('**/api/follow/credentials', (route) => route.fulfill(json({ providers: [] })));
/* 服务端的定时检查可能正在跑,那一趟会让检查键挂着 aria-busy,settle 等不到头。 */
@@ -135,4 +149,18 @@ describe('关注的出处用站点图标', () => {
await opened.close();
}
});
+
+ it('卡面换成别的站那条时,另见列主条目的站、不列卡面自己的站', { timeout: 60_000 }, async () => {
+ const opened = await openFollow(browser, '/follow', '[data-follow-item="12"] .fbadge.dup');
+ try {
+ const card = opened.page.locator('[data-follow-item="12"]');
+ const shown = await card.locator('.pic > .badge').getAttribute('title');
+ const alts = await card.locator('.fbadge.dup img').evaluateAll((icons) =>
+ icons.map((icon) => icon.getAttribute('alt')));
+ assert.equal(shown, 'Rule34.xxx', '卡面没有换成有视频的那条');
+ assert.deepEqual(alts, ['pixivFANBOX', 'Pawchive'], `另见列的站不对:${JSON.stringify(alts)}`);
+ } finally {
+ await opened.close();
+ }
+ });
});
diff --git a/web/app.js b/web/app.js
index e52d35fc7..21c29b6f3 100644
--- a/web/app.js
+++ b/web/app.js
@@ -5968,7 +5968,7 @@ function followDetailTags(item){
}
/* 正文不报组里有几条:条数只由封面角标报一次,数的是合并了几个媒体(`followStack`)。 */
-function followBadges(group){
+function followBadges(group,shown=group.primary){
const badges=[];
/* WIP 说的是这一条,不是这一组。`2B Camp [4K]` 判的是 alt,只因为同组还有一条
`[WIP]` 就在它头上挂 WIP,读起来就成了「这一条是半成品」。同组有 WIP 仍然要
@@ -5976,9 +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>`);
- /* 另见的站用站点图标列出,站名落在图标的 alt 与徽章的 title 上;没登记图标的站写站名。 */
- if(group.duplicates.length){
- const sites=new Map(group.duplicates.map(d=>[d.provider,d.provider_label||d.provider]));
+ /* 另见的站用站点图标列出,站名落在图标的 alt 与徽章的 title 上;没登记图标的站写站名。
+ 「另见」相对卡面这一条(`shown`)说:主条目没有当前视图的媒体时,卡面换成组里别的站
+ 那条,这时主条目的站才是另见,卡面自己的站不再列。 */
+ const sites=new Map([group.primary,...group.variants,...group.duplicates]
+ .filter(member=>member.provider!==shown.provider)
+ .map(member=>[member.provider,member.provider_label||member.provider]));
+ if(sites.size){
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>`);
@@ -6407,7 +6411,7 @@ function followCard(group,authorSources=[]){
/* 角标与翻卡都取服务端对整组的判定(`group.stack`):同一个画面只翻一次,跨站重复算来源。 */
const {isMix,label:mixLabel,glyph:mixGlyph,faces:faceUrls}=followStack({cover:thumbUrl,
coverFace:(selectedMedia?.thumb_url?selectedMedia:item).face,stack:group.stack,imageView,limit:MIX_FLIP_FACES});
- const badges=followBadges(group);
+ const badges=followBadges(group,item);
const author=followAuthorName(authorSources)||item.author||item.source_label||'创作者未取得';
const when=followWhen(item),compactWhen=/^\d{4}-/.test(when)
?(when.startsWith(String(new Date().getFullYear()))?when.slice(5,10):when.slice(0,10)):when;