Peach: Local-first video metadata scraper and media manager.
fix(follow): 任务面板与作者范围检查
longmeidaoeeaaf9aff6b6
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.mdindex 7ad6e19d9..0797f5181 100644--- a/docs/HANDOFF.md+++ b/docs/HANDOFF.md@@ -5,7 +5,7 @@## 界面、媒体与复核的既定判据-- 后台任务与断线恢复见 `docs/REUSE.md`。+- 后台任务、进度容器与断线恢复见 `docs/REUSE.md`。页面密度、控件、提示与响应式的实现门槛见 `.claude/skills/peach-web-ui/SKILL.md`,这里只留代码看不出来的判据。diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 04cbdf1b8..8b19e04aa 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -6,6 +6,7 @@## 复用决策门槛- 删除失效链接与资源同步的执行阶段复用 `BackgroundJob.start_result` 保存终态回执;刷新只查状态,写入请求不自动重放,原有确认与检查结果过期门槛保持有效。+- 关注进度复用 Fieldset 与 Progress;完成时保留内容取数,按作者检查复用 `sources` 范围参数,报错作者复用现有身份解析。无新依赖;参考取证见 `reference-snapshots/vercel-geist-note-progress-switch-analytics.md`。- 关注检查、来源查找和口味刷新复用 `jobs.BackgroundJob`,浏览器状态跟进放在 `frontend/src/jobs.ts`;不新增队列或调度依赖。HTTP 继续使用固定的 HTTPX 0.28.1(BSD-3-Clause)和 curl_cffi 0.16.2(MIT),支持现有 Python 3.12+ 与 Windows/macOS 打包。[HTTPX 原生重试](https://www.python-httpx.org/advanced/transports/)只覆盖连接失败,无法统一两个 transport 的读超时、临时 HTTP 状态与页面进度,因此由现有连接器负责 GET 重试策略。截图中的 TLS 握手超时作为隔离 transport 输入,验证第 5 次成功、耗尽、403 单次终止和 POST 不重放;不新增依赖体积。任务状态保存在服务进程,浏览器刷新后通过读接口恢复;服务重启不自动重放任务。diff --git a/docs/reference-snapshots/vercel-geist-note-progress-switch-analytics.md b/docs/reference-snapshots/vercel-geist-note-progress-switch-analytics.mdindex 9419b20a7..53d669e31 100644--- a/docs/reference-snapshots/vercel-geist-note-progress-switch-analytics.md+++ b/docs/reference-snapshots/vercel-geist-note-progress-switch-analytics.md@@ -65,6 +65,16 @@## Peach 有意差异+### 关注任务容器复核(2026-09-05)++HTTPX 取得 `https://vercel.com/geist/fieldset` 当前 HTML,SHA-256 为+`6a5bde91b9d131014d4837763227457711eee2575e68994a1d9c51a44948aa0c`。+正文提供 Without Footer 示例,DOM 使用 `group/fieldset material-base`、正文 `p-5`;+关注任务复用现有 Fieldset 的 20px 正文内边距、项目表面 token 与真实来源计数 Progress,+不加无动作的页脚。官方浏览器读取两次报 `js execution timed out; kernel reset`,+当前交互与计算样式未取得;本地桌面与手机另行验收,不把 HTML 取证说成视觉验收。+此段是人工笔记,不登记到可变上游快照注册表。+- Peach 是无构建的原生 HTML/CSS/ES module,不引入 Geist React 包;复用语义、状态与可测量层级,统一实现位于 `web/js/ui-components.js`。- `/stats` 当前没有环境与日期参数,不复制无消费者的筛选器;使用有 ARIA 的指标 tab 切换库存、观看、覆盖和系统盘主详情,再用同层 tablist 切换标签、最近观看和标签来源。diff --git a/frontend/src/jobs.ts b/frontend/src/jobs.tsindex aecb7897a..bb7e528b8 100644--- a/frontend/src/jobs.ts+++ b/frontend/src/jobs.ts@@ -50,6 +50,7 @@ export function followJobProgress(options: {note: (text: string) => string;loading: (text: string) => string;progress: (value: number, max: number) => string;+ container?: (content: string) => string;storageKey?: string;title?: string;watchIdle?: boolean;@@ -80,8 +81,9 @@ export function followJobProgress(options: {? `${state.older ? '抓取历史' : '检查更新'}:已完成 ${state.checked || 0}/${state.total} 个来源`: '正在准备检查任务…'))+ (current ? ` · ${current.label || current.provider || ''}${attempt}` : '');- panel.innerHTML = options.loading(text)+ const content = options.loading(text)+ ((state.total || 0) > 0 ? options.progress(state.checked || 0, state.total!) : '');+ panel.innerHTML = options.container ? options.container(content) : content;} else if (tracked && tracked === state.job_id) {tracked = undefined;settled = true;diff --git a/frontend/test/jobs.test.ts b/frontend/test/jobs.test.tsindex 1ce404e54..ce338690c 100644--- a/frontend/test/jobs.test.ts+++ b/frontend/test/jobs.test.ts@@ -12,9 +12,11 @@ describe('后台任务状态恢复', () => {current: {label: '演示来源', attempt: 3, max_attempts: 5, retry_in: 2}};const mount = (element: HTMLElement) => followJobProgress({host: element,active: () => true, read: async () => state, busy: () => {}, complete,- note: text => text, loading: text => text, progress: () => ''});+ note: text => text, loading: text => text, progress: () => '',+ container: content => `<section data-geist-fieldset>${content}</section>`});mount(host); await vi.advanceTimersByTimeAsync(0);expect(host.textContent).toContain('1/3');+ expect(host.querySelector('[data-geist-fieldset]')).not.toBeNull();expect(host.textContent).toContain('第 3/5 次尝试');host.remove();const fresh = document.createElement('div'); document.body.append(fresh);diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex d6fcbe1dd..4d8b73a4b 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -879,16 +879,18 @@ def _run_follow_check(contract, body, job_id=None) -> dict:for row in rows:if job_id and contract.follow_job.snapshot() is None:break- current = {"source": row["id"], "label": row["label"],+ current = {"source": row["id"], "label": _author_display_name(row),"provider": PROVIDER_LABELS.get(row["provider"], row["provider"])}def progress(**fields):if job_id:contract.follow_job.update(job_id, total=len(rows), checked=len(results),results=results.copy(), current={**current, **fields})progress(attempt=1, max_attempts=5, retry_in=0)- results.append(_check_payload(run_check(+ result = _check_payload(run_check(row, credentials=credentials, writer=writer,- connector_factory=build_connector, older=older, progress=progress)))+ connector_factory=build_connector, older=older, progress=progress))+ result["author"] = _author_display_name(row)+ results.append(result)progress()return {"ok": True, "checked": len(results), "results": results}diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex e9ae5ff5e..31c1d67f6 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -100,6 +100,13 @@ class FollowContractTests(unittest.TestCase):self.assertEqual([row['source'] for row in result['results']], [selected])self.assertEqual(factory.call_count, 1)+ def test_failed_numeric_source_has_a_readable_author(self):+ source = self._seed(ref='patreon/12387984', label='Pantsushi · patreon')+ with mock.patch.object(web_follow, 'build_connector') as factory:+ factory.return_value.fetch.side_effect = FollowSourceError('offline')+ result = self._post('/api/follow/check', {'sources': [source]})+ self.assertEqual(result['results'][0]['author'], 'Pantsushi')+def test_background_prune_keeps_the_confirmation_and_expiry_gate(self):refused = self._post('/api/links/prune', {'background': True})self.assertFalse(refused['ok'])@@ -1482,6 +1489,19 @@ class FollowWebSourceTests(unittest.TestCase):if needle not in self.page:self.fail(f"Web 表面缺少:{needle!r}" + (f"({message})" if message else ""))+ def test_follow_task_controls_keep_content_and_name_the_author(self):+ self.assertPageContains('data-follow-sources=')+ self.assertPageContains('group.filter(s=>s.enabled).map(s=>s.id)')+ self.assertPageContains('aria-label="检查 ${esc(name)} 的全部来源"')+ self.assertPageContains('row.author||row.label||row.ref')+ self.assertPageLacks('个来源上次检查失败,原因见对应那一行。')+ refresh = self.page.split('async function refreshFollowSurface(surface){', 1)[1].split('async function wireOperationProgress', 1)[0]+ self.assertNotIn('showManagementBody', refresh)+ self.assertNotIn('scrollTo', refresh)+ click = self.page.split("root.querySelectorAll('[data-follow-check]').forEach", 1)[1].split('const saveAuthorAlias', 1)[0]+ self.assertNotIn('openFollowManage', click)+ self.assertIn('wireFollowProgress()', click)+def assertPageLacks(self, needle, message=""):if needle in self.page:self.fail(f"Web 表面不应出现:{needle!r}" + (f"({message})" if message else ""))diff --git a/tests/test_web_ui.py b/tests/test_web_ui.pyindex 5a84bfa26..b8605d305 100644--- a/tests/test_web_ui.py+++ b/tests/test_web_ui.py@@ -3135,8 +3135,7 @@ class WebUiSourceTests(unittest.TestCase):# 每一条失败都进 Note,没有第二套「红字一行」的写法:红色文字既没有图标# 也没有边框,在暗色底上和普通说明文字只差一个色相,扫读时整条会被跳过。self.assertPageContains('class="geist-note geist-note-error fwarn" role="alert"')- self.assertPageContains(- "noteHtml(`${broken.length} 个来源上次检查失败,原因见对应那一行。`,{variant:'error'})")+ self.assertPageContains("${followCheckReport?followCheckFailNote(followCheckReport):''}")self.assertPageContains("noteHtml('文件权限过宽,请在运行 Peach 的 POSIX 主机上收紧为 0600。',{variant:'error'})")self.assertPageLacks('class="fnote warn"')diff --git a/web/app.js b/web/app.jsindex 31b6ed5ee..737c030c6 100644--- a/web/app.js+++ b/web/app.js@@ -4182,8 +4182,8 @@ function followCheckFailNote(report){.filter(Boolean).join(' '))}:没有更多历史内容</p>`).join('')}</div>${dismiss}</div>`:'';const errors=failed.length||evidence.length?`<div class="geist-note geist-note-error fcheckreport" role="alert">${icon('alert')}<div>${failed.length?`<p><b>${failed.length} 个来源检查失败</b></p>`:''}- ${failed.map(row=>`<p class="fcheckfail">${esc([row.provider_label||row.provider,row.ref]- .filter(Boolean).join(' '))}${row.provider?':':''}${esc(row.error||'未说明原因')}</p>`).join('')}+ ${failed.map(row=>`<p class="fcheckfail"><strong>${esc(row.provider_label||row.provider||'')}</strong>+ <strong>${esc(row.author||row.label||row.ref||'')}</strong>${row.provider?':':''}${esc(row.error||'未说明原因')}</p>`).join('')}${evidence.length?`<p class="fchecknote">候选已入库,但这一次的原始响应没有留档:${esc(evidence[0].evidence_error)}</p>`:''}</div>${dismiss}</div>`:'';@@ -4352,7 +4352,8 @@ function followBackfillState(sources){所以往回抓是一个独立的、显式的动作,点一次走一页,不自动、不连翻。 */async function wireFollowProgress(){const host=$('#stats').querySelector('.followmanage')||$('#stats'),surface=surfaceToken(surfacePath());- const marker=document.createElement('div');host.prepend(marker);+ host.querySelector('[data-follow-progress]')?.remove();+ const marker=document.createElement('div');marker.dataset.followProgress='';host.prepend(marker);const ui=await import('/dist/peach-ui.js');if(!surfaceCurrent(surface)||!marker.isConnected)return;ui.followJobProgress({host:marker,active:()=>surfaceCurrent(surface),@@ -4362,10 +4363,22 @@ async function wireFollowProgress(){complete:report=>{followCheckReport=report.status==='failed'?{results:[{ok:false,error:report.error}]}:report;followCheckToast(followCheckReport);- if(surfaceCurrent(surface))void (surface.path==='/follow-manage'?openFollowManage(false):openFollow(false))},+ if(surfaceCurrent(surface))void refreshFollowSurface(surface)},note:text=>noteHtml(text,{label:'任务状态'}),loading:text=>loadingDotsHtml(text),+ container:content=>`<section class="followtask" data-geist-fieldset aria-label="检查更新进度"><div class="geist-fieldset-content">${content}</div></section>`,progress:(value,max)=>progressHtml(`已完成 ${value}/${max} 个来源`,value,max)});}+async function refreshFollowSurface(surface){+ try{+ const [data,credentials]=await Promise.all([+ surfaceApi(surface,surface.path==='/follow-manage'?'/api/follow?limit=1':followPageUrl(0)),+ surfaceApi(surface,'/api/follow/credentials')]);+ if(!surfaceCurrent(surface))return;+ followData=data;+ if(surface.path==='/follow-manage')renderFollowManage(credentials);+ else renderFollow();+ }catch(error){if(surfaceCurrent(surface))toast(error.message,{warn:true})}+}async function wireOperationProgress({host,path,key,title,busy,complete}){if(!host)return;host.querySelector('[data-operation-progress]')?.remove();@@ -4404,7 +4417,7 @@ function wireFollowOlder(){const started=await api('/api/follow/check',{method:'POST',body:JSON.stringify({older:true,background:true})});sessionStorage.setItem('peach-follow-job',started.job_id);- if(button.isConnected)await openFollow(false);+ if(button.isConnected)void wireFollowProgress();}catch(error){followCheckReport={results:[{ok:false,error:error.message}]};followCheckToast(followCheckReport);@@ -4546,6 +4559,8 @@ function followAuthorBlock(group){return `<div class="fauthor${bad?' bad':''}"><div class="fauthorhead">${followAuthorAvatar(group)}<b>${esc(name)}</b>+ <button type="button" class="frowicon" data-follow-check="" data-follow-sources="${group.filter(s=>s.enabled).map(s=>s.id).join(',')}"+ ${group.some(s=>s.enabled)?'':'disabled'} title="检查此作者" aria-label="检查 ${esc(name)} 的全部来源">${icon('refresh-cw')}</button><span class="fmeta"${group.length>1?` title="${group.length} 个来源"`:''}>${group.length>1? group.map(source=>sourceIcon(source.provider)).join(''): sourceIcon(group[0].provider)+esc(group[0].provider_label)}</span>@@ -4725,7 +4740,6 @@ function renderFollowManage(credentials){icon('refresh-cw')}检查全部</button><button class="fbtn" data-follow-view>${icon('rss')}去看更新</button></div>${followCheckReport?followCheckFailNote(followCheckReport):''}- ${broken.length?noteHtml(`${broken.length} 个来源上次检查失败,原因见对应那一行。`,{variant:'error'}):''}${sources.length?`<div class="frows fsources" data-layout="${followListLayout()}">${followAuthorGroups(sources).map(followAuthorBlock).join('')}</div>${counts.new?`<div class="fsecfoot"><p class="fnote fbulkrow"><span class="fbulkcounts">未看 ${counts.new} · 已看 ${counts.seen||0}@@ -4924,7 +4938,7 @@ function wireFollowManage(){});root.querySelectorAll('[data-follow-check]').forEach(button=>button.onclick=async()=>{if(followBusy)return;- followBusy=true;const oldTitle=button.title;+ followBusy=true;let startedJob=false;const oldTitle=button.title;const oldAria=button.getAttribute('aria-label');const oldButton=button.innerHTML;setActionBusy(button);button.title='检查中…';@@ -4932,10 +4946,13 @@ function wireFollowManage(){button.innerHTML=`${spinnerHtml('检查中')}${button.matches('.frowicon')?'':'<span>检查中…</span>'}`;try{const id=button.dataset.followCheck;+ const sources=button.dataset.followSources?.split(',').filter(Boolean).map(Number);const started=await api('/api/follow/check',{method:'POST',- body:JSON.stringify({...(id?{source:+id}:{}),background:true})});+ body:JSON.stringify({...(sources?{sources}:id?{source:+id}:{}),background:true})});sessionStorage.setItem('peach-follow-job',started.job_id);- if(button.isConnected)await openFollowManage(false);+ followCheckReport=null;root.querySelector('.fcheckreports')?.remove();+ startedJob=true;+ if(button.isConnected)void wireFollowProgress();}catch(e){// 整个请求就失败了(断网、写入端不可达):同样走那块报告,不弹 alert。followCheckReport={results:[{ok:false,error:e.message}]};@@ -4945,7 +4962,7 @@ function wireFollowManage(){if(box)box.outerHTML=note;else $('#stats').querySelector('.fsec')?.insertAdjacentHTML('afterbegin',note);}- finally{if(button.isConnected)followBusy=false;setActionBusy(button,false);button.innerHTML=oldButton;+ finally{if(button.isConnected)followBusy=startedJob;setActionBusy(button,startedJob);button.innerHTML=oldButton;button.title=oldTitle;if(oldAria===null)button.removeAttribute('aria-label');else button.setAttribute('aria-label',oldAria)}});diff --git a/web/css/22-followmanage.css b/web/css/22-followmanage.cssindex d7f96de84..4b5f0766e 100644--- a/web/css/22-followmanage.css+++ b/web/css/22-followmanage.css@@ -179,7 +179,12 @@放前面的话选择器里的同名片段会被先匹配到,取回来的是这里的规则。 */.fauthor{box-sizing:border-box;height:280px;padding:8px 12px;border:1px solid var(--border-10);border-radius:var(--control-radius);background:var(--surface);display:grid;grid-template-rows:auto minmax(0,1fr)}+.followtask{border:1px solid var(--border-10);border-radius:var(--surface-radius);background:var(--surface);margin-bottom:16px}+.followtask>.geist-fieldset-content{padding:20px;min-width:0;overflow-wrap:anywhere}+.followmanage .followtask{margin-bottom:0}+.fcheckfail strong{font-weight:600}.fauthorhead{display:flex;align-items:center;gap:9px;padding:10px 0 6px}+.fauthorhead>.frowicon{flex-shrink:0}.fauthorhead b{font-size:var(--fs-md);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.fauthorhead .fmeta{margin-left:auto;flex:0 1 auto;min-width:0;white-space:nowrap}@@ -295,6 +300,7 @@ details.fcred{display:block}.fcredactions [data-cred-state]{font-size:var(--fs-xs);color:var(--muted)}@media (max-width:640px){+ .fauthorhead>.frowicon{width:44px;height:44px}.fsec{padding:12px 13px 14px}.fsechead{margin:-12px -13px 12px;padding:12px 13px}.fsecfoot{margin:14px -13px -14px;padding:12px 13px}diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.jsindex 0494d8f1e..ee3a1e070 100644--- a/web/dist/peach-ui.js+++ b/web/dist/peach-ui.js@@ -943,8 +943,8 @@ function Ct(e) {let o = a.status === "running";if (e.host.hidden = !o, e.busy(o), o) {r = a.job_id, r && sessionStorage.setItem(n, r);- let i = a.current, o = (i?.attempt || 1) > 1 ? ` · 第 ${i?.attempt}/${i?.max_attempts} 次尝试${i?.retry_in ? `,${i.retry_in} 秒后重试` : ""}` : "", s = (e.title || (a.total ? `${a.older ? "抓取历史" : "检查更新"}:已完成 ${a.checked || 0}/${a.total} 个来源` : "正在准备检查任务…")) + (i ? ` · ${i.label || i.provider || ""}${o}` : "");- t.innerHTML = e.loading(s) + ((a.total || 0) > 0 ? e.progress(a.checked || 0, a.total) : "");+ let i = a.current, o = (i?.attempt || 1) > 1 ? ` · 第 ${i?.attempt}/${i?.max_attempts} 次尝试${i?.retry_in ? `,${i.retry_in} 秒后重试` : ""}` : "", s = (e.title || (a.total ? `${a.older ? "抓取历史" : "检查更新"}:已完成 ${a.checked || 0}/${a.total} 个来源` : "正在准备检查任务…")) + (i ? ` · ${i.label || i.provider || ""}${o}` : ""), c = e.loading(s) + ((a.total || 0) > 0 ? e.progress(a.checked || 0, a.total) : "");+ t.innerHTML = e.container ? e.container(c) : c;} else if (r && r === a.job_id) r = void 0, i = !0, e.host.hidden = a.status !== "failed", sessionStorage.removeItem(n), t.innerHTML = a.status === "failed" ? e.note(a.error || "检查失败") : "", e.complete(a);else {if (r && a.status === "idle") {