Peach: Local-first video metadata scraper and media manager.
fix: refine follow management results
longmeidao954f9356c25f
diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.pyindex 17530d75f..b61980794 100644--- a/src/peach/follow_sources.py+++ b/src/peach/follow_sources.py@@ -616,7 +616,9 @@ class Rule34XxxConnector(_BaseConnector):body = response.body.decode("utf-8", errors="replace").strip()if body.startswith('"') and "authentication" in body.lower():raise CredentialError("rule34xxx 拒绝了 user_id/api_key")- payload = self._json(response)+ # rule34.xxx 在标签没有任何帖子时返回 HTTP 200 + 空正文,不是 JSON `[]`。+ # 这只代表零命中;非空但无法解析的响应仍按结构异常报告,避免吞掉站点改版。+ payload = [] if not body else self._json(response)posts = payload.get("post", []) if isinstance(payload, dict) else payloadif not isinstance(posts, list):raise FollowSourceError("rule34xxx 的帖子列表格式不符")diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.pyindex 21488365b..db93e1138 100644--- a/tests/test_follow_sources.py+++ b/tests/test_follow_sources.py@@ -490,6 +490,13 @@ class Rule34XxxConnectorTests(unittest.TestCase):connector.fetch("lazyprocrastinator")self.assertEqual(seen, [])+ def test_an_empty_success_response_means_the_tag_has_no_posts(self):+ # rule34.xxx 的零命中响应是 HTTP 200 + 空正文,不是 JSON `[]`。+ # 不能把普通的「搜不到」显示成红色 JSON 错误。+ result = self._connector(body=b" \r\n").fetch("not-a-real-tag")+ self.assertEqual(result.candidates, ())+ self.assertEqual(result.raw_body, b" \r\n")+def test_the_declared_origin_becomes_a_cross_site_group_key(self):# 同一个 fanbox 帖在 source 里有两种写法,必须归一到同一个键——而那串数字# 正是 kemono 上同一帖子的 post id,跨站重复因此能精确命中。diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex c684bc0e1..73dc01bad 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -723,6 +723,28 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains("data-pick-add")self.assertPageContains("data-pick-cancel")+ def test_lookup_results_stay_inside_the_add_section_with_one_title_scale(self):+ page = self.page+ manage = page[page.index("function renderFollowManage("):+ page.index("function wireFollowItems(")]+ add_section = manage[manage.index('<section class="fsec">'):+ manage.index('</section>')]+ self.assertIn('id="followPicks"', add_section)+ self.assertNotIn('</section>\n <div id="followPicks">', manage)+ self.assertPageContains(+ '<div class="fpicks"><div class="fsechead"><h3>查找结果</h3>')+ self.assertPageContains('<p class="fpickempty">没有查到来源</p>')+ self.assertNotIn(".fpicks h3{", page,+ "查找结果不应另起一套标题字号")++ def test_follow_sources_use_multiple_columns_and_link_to_the_original_page(self):+ self.assertPageContains('class="frows fsources"')+ grid = self.page[self.page.index(".fsources{"):]+ self.assertIn("repeat(auto-fit,minmax(430px,1fr))", grid[:grid.index("}")])+ self.assertPageContains('class="fsourcelink" href="${esc(source.url)}"')+ self.assertPageContains('title="打开原来源"')+ self.assertPageContains('rel="noreferrer noopener"')+def test_already_followed_candidates_are_shown_but_not_selectable(self):# 灰掉但仍显示,免得人以为没查到。self.assertPageContains("c.known?' known':''")@@ -871,7 +893,8 @@ class FollowWebSourceTests(unittest.TestCase):token,且一个字面像素都不留」。"""page = self.page- block = page[page.index("/* ── 关注管理页 ──"):page.index("/* ── 查找结果的勾选清单")]+ # 查找结果现在属于同一个管理分区,所以字号检查也要覆盖这一段,直到关注页脚。+ block = page[page.index("/* ── 关注管理页 ──"):page.index("/* 关注页底部")]self.assertEqual(re.findall(r"font-size:[\d.]+px", block), [],"面板里不该再有写死的字号")steps = sorted({m for m in re.findall(r"font-size:var\(--fs-([a-z0-9]+)\)", block)})diff --git a/web/app.css b/web/app.cssindex 6faf083bb..1778b0ae5 100644--- a/web/app.css+++ b/web/app.css@@ -1333,6 +1333,7 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位容器和每一项都要显式 min-width:0 才会真的收缩。 */.frows{display:grid;min-width:0}.frows>*{min-width:0}+.fsources{grid-template-columns:repeat(auto-fit,minmax(430px,1fr));gap:0 22px}.frow{display:flex;align-items:center;gap:12px;padding:9px 0;flex-wrap:wrap;border-bottom:1px solid var(--border-10)}.frows>.frow:last-child{border-bottom:0}@@ -1342,6 +1343,8 @@ body.drawer-open .edge{opacity:0;pointer-events:none} /* 展开时窄栏让位.frow .fmeta{flex:0 0 auto}.frowerr{flex:1 1 100%;margin:2px 0 0;font-size:var(--fs-sm);line-height:1.6;color:var(--drop)}.fsource.bad>b{color:var(--drop)}+.fsourcelink{color:inherit;text-decoration:none}+.fsourcelink:hover{text-decoration:underline;color:var(--tungsten)}/* 作者分组。同一个人在几个站上是几条来源、一个人,所以头像和名字只出现一次,下面才是各站那几行。分组之间用发丝线隔开,不套框——按 vercel-report-design,@@ -1414,15 +1417,17 @@ details.fcred{display:block}.faddform{flex-wrap:wrap}.faddform .fbtn{flex:1 1 100%}.frow{gap:8px}+ .fsources{grid-template-columns:1fr}.frow .fmeta:nth-of-type(2){display:none}}-/* ── 查找结果的勾选清单 ── */-.fpicks{margin:0 0 18px;padding:14px;border:1px solid var(--line-soft);border-radius:12px;background:var(--surface)}-.fpicks h3{margin:0 0 10px;font-size:var(--fs-lg)}+/* 查找结果属于「添加关注」这一个动作,留在同一容器里;发丝线只分阶段,不再另套卡片。 */+.fpicks{margin:14px 0 0;padding:14px 0 0;border-top:1px solid var(--border-10)}+.fpicks .fsechead{margin-bottom:10px}.fpick{margin-bottom:12px}.fpick>b{display:block;font-size:var(--fs-xs);color:var(--muted);margin-bottom:5px;overflow-wrap:anywhere}.fpick.bad>b{color:var(--drop)}+.fpickempty{margin:7px 0;color:var(--muted);font-size:var(--fs-sm)}.fpick p{margin:2px 0;font-size:var(--fs-xs);color:var(--muted)}.fpick.bad p{color:var(--drop)}.fpickitem{display:flex;gap:9px;align-items:flex-start;padding:6px 9px;border:1px solid var(--border-10);border-radius:8px;margin-bottom:4px;cursor:pointer;font-size:var(--fs-xs)}diff --git a/web/app.js b/web/app.jsindex ddfd95386..38ef3da11 100644--- a/web/app.js+++ b/web/app.js@@ -1636,7 +1636,8 @@ function followSourceRow(source){const state=source.last_status||'未检查';const bad=state==='error'||state==='unauthorized';return `<div class="frow fsource${bad?' bad':''}">- <b>${esc(source.label)}</b>+ <b><a class="fsourcelink" href="${esc(source.url)}" target="_blank"+ rel="noreferrer noopener" title="打开原来源">${esc(source.label)}</a></b><span class="fmeta">${sourceIcon(source.provider)}${esc(source.provider_label)}</span><span class="fmeta">${esc(source.last_checked_at?localTime(source.last_checked_at):'未检查')}</span><span class="fmeta${bad?' warn':''}">${esc(state)}</span>@@ -1720,8 +1721,8 @@ function renderFollowManage(credentials){${(followData.suggestions||[]).length?`<div class="fguess"><span class="fmeta">猜你喜欢</span>${followSuggestionChips(followData.suggestions)}</div>`:''}+ <div id="followPicks"></div></section>- <div id="followPicks"></div><section class="fsec"><div class="fsechead"><h3>关注列表</h3><span class="fmeta">${sources.length} 个来源${@@ -1731,7 +1732,7 @@ function renderFollowManage(credentials){<button class="fbtn" data-follow-view>${icon('globe')}去看更新</button></div>${followCheckReport?followCheckSummary(followCheckReport):''}${broken.length?`<p class="fnote warn">${broken.length} 个来源上次检查失败,原因见对应那一行。</p>`:''}- ${sources.length?`<div class="frows">${+ ${sources.length?`<div class="frows fsources">${followAuthorGroups(sources).map(followAuthorBlock).join('')}</div>${counts.new?`<p class="fnote">未看 ${counts.new} · 已看 ${counts.seen||0}· 已保存 ${counts.saved||0} · 已忽略 ${counts.ignored||0}@@ -1945,16 +1946,16 @@ function renderFollowPicks(results){<span><b>${esc(c.provider_label)}</b> ${esc(c.label)}<i>${esc(c.known?'已经在追':c.evidence)}</i></span></label>`).join('');return `<div class="fpick"><b>${esc(row.line)}</b>- ${items||'<p class="empty">这一条没有查到任何来源</p>'}+ ${items||'<p class="fpickempty">没有查到来源</p>'}${failures.length?`<p class="fpickfail">${failures.map(([k,v])=>`${esc(k)}:${esc(v)}`).join(';')}</p>`:''}</div>`;}).join('');const total=results.reduce((n,row)=>n+(row.candidates||[]).filter(c=>!c.known).length,0);- box.innerHTML=`<section class="fpicks"><h3>查找结果</h3>${blocks}+ box.innerHTML=`<div class="fpicks"><div class="fsechead"><h3>查找结果</h3></div>${blocks}${total?`<div class="fpickactions"><button data-pick-add>添加选中</button><button data-pick-cancel>取消</button><span data-pick-state aria-live="polite"></span></div>`- :'<div class="fpickactions"><button data-pick-cancel>关闭</button></div>'}</section>`;+ :'<div class="fpickactions"><button data-pick-cancel>关闭</button></div>'}</div>`;box.querySelector('[data-pick-cancel]').onclick=()=>{box.innerHTML=''};const addButton=box.querySelector('[data-pick-add]');if(addButton)addButton.onclick=async()=>{