Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(follow): rule34.xxx 标签与出处 URL 入库前反转义

longmeidao70a6216a6253
diff --git a/docs/STATUS.md b/docs/STATUS.md
index e3d5801f0..400ba6ac6 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -36,6 +36,7 @@
## 本批修正与验证
+- 2026-08-29 修关注页 tag 转义(用户报告 `'` 显示成 `'`):rule34.xxx 的 dapi 返回 HTML 转义形态,实体原样入库、页面二次转义后显示成字面量;真实账本 132 行中招(131 行 rule34xxx 的 tags、12 行标题、3 行 source URL),全部 `new` 状态。入库侧连接器统一反转义 tags 与 source URL(归组键只取 path,既有分组不受影响);读取侧 `_item_tags` 与条目标题在出口幂等归一——旧行不写账本即恢复正常显示与筛选,同一标签的脏/净写法合并为同一身份。其余主要 tag 面排查干净:Rule34Video/Paheal 走 BeautifulSoup 已解码,目录 `/api/index`(tags/performers/studios)与 `asset_tag` 词汇 0 命中,fanbox 行的 `&` 是合法字符非实体。follow 430 项通过。账本存量实体的物理清理待另行授权;当前读取层已归一,展示与筛选不受影响。
- 2026-08-29 按用户复核意见改两处关注反馈:检查回执 toast 带具名动作「去看更新」(点击关掉自己并跳转关注流),统计文案收掉悬空的「条详情」——它曾被当成可点的链接;关注管理的批量操作(全部标记已看/全部忽略)从计数行内的裸链接改为独立 `.fbulk` 行的 `.fbtn` 次级按钮,与本页「检查全部/去看更新」同一套控件语言。follow 427 项通过;生产页面实测:toast 动作点击后正确跳转 `/follow`,批量按钮渲染正常,全程未触发真实检查、未写 ledger。
- 2026-08-29 关注检查反馈对齐 Geist toast 处方(取证:`docs/reference-snapshots/vercel-geist-toast.md`):「检查了 N 个来源」改为右下角 toast(挂 body 直下,整页重画冲不掉,自动消失、hover 暂停、右上角关闭,`aria-live="polite"`);失败只发一句短 toast,原因明细留在管理页内的持久行(`.fcheckreport`,左侧红条 + 恢复入口),关注页的持久失败状态走重排后的 `.fwarn`(图标 + 行内链接,修掉链接前 10px 死间距与缩小字号)。全站转圈动画并成一套 `peach-spin`:检查更新、检查全部、抓更早的一页、扫描差异、同步并清理、读取浏览器、顶栏换一批统一为按钮 busy 类 + 图标自转,「抓更早的一页」不再丢图标。新增顶栏「审查遮挡」开关(`#censorBtn`):默认开启——封面与预览图以原始画面进截图会被截图管道的审查拦下(关注页实测),localStorage 只记用户显式关闭;开启后全站内容图与视频(含 videojs 海报层、悬停预览、沉浸模式、关注流封面/详情海报/图片墙)统一重糊去饱和压暗,悬停预览同时不再启动;品牌标与来源 favicon 豁免。上一轮遗留的 4 处 catalog 源码契约(settingscard 主题覆盖顺序、滑杆轨道 pill 字面量、换一批重置种子精确串、搜索聚焦环 color-mix 断言)一并修正,`follow` 426 项、`catalog` 405 项通过。
- 2026-08-29 按检视报告做架构优化,六批独立提交、每批全量回归。`web_contract.py` 3294 → 1899 行:资源对账拆为 `web_resource_sync`,复核队列拆为 `web_review`,两者都用 Protocol 只声明各自需要的能力;拆分暴露的三处循环依赖靠下沉纯规则解决(`dir_expr`/`GENERIC_PHOTO_DIRS`/`photo_set_title` → `catalog_rules`,`_resolve_entity` → `entities.resolve_entity`)。`web_logic.py` 改名 `catalog_rules.py`——那 206 行没有一行是 web 的却被数据层依赖,倒置的是名字不是方向;新增 `test_module_layering` 锁住分层。follow 域:删除 ADR-0007 的 RSS 适配层与 `feedparser` 依赖(ADR-0007 已标 Superseded by 0019),provider 元数据收进 `follow_providers` 单点登记表(凭据策略刻意留在 `CREDENTIAL_GUIDE`),八个连接器的取回骨架抽成 `_BaseConnector._request()`,探测能力转正为 `probe`/`fetch_json`/`parse_json`。`w_item_tag` 改走 `write_transaction`,顺带修掉「除资产不存在外任何 execute 抛出都既不回滚也不关连接」。`test_rm_web.py` 2428 → 1512 行,测试随领域同批拆出;拆带 patch 的域时 patch 目标必须跟着代码走,否则静默失效。全量 1188 → 1206 项通过。
diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.py
index b6e5aa01b..0d205011e 100644
--- a/src/peach/follow_sources.py
+++ b/src/peach/follow_sources.py
@@ -8,6 +8,7 @@
"""
from __future__ import annotations
+import html
import json
import re
import urllib.parse
@@ -894,7 +895,10 @@ class Rule34XxxConnector(_BaseConnector):
def _candidate(self, post: dict, tag: str) -> FollowCandidate:
post_id = str(post.get("id") or "")
- tags = str(post.get("tags") or "")
+ # dapi 返回的标签是 HTML 转义形态(实测 `miqo'te`)。实体不反转义
+ # 就进 metadata,读取层再转一次就成了双重转义,用户看到的就是 `'`
+ # 字面量,同一个标签还会和反转义后的写法分裂成两个身份。
+ tags = html.unescape(str(post.get("tags") or ""))
image = str(post.get("image") or "")
stem = re.sub(r"\.[a-z0-9]{2,5}$", "", image, flags=re.IGNORECASE)
# booru 帖子没有标题。实测 rule34.xxx 的 `image` 全是 32 位十六进制哈希,
@@ -909,7 +913,10 @@ class Rule34XxxConnector(_BaseConnector):
title_from, title_is_name = "tags", False
# 出处比站内父帖强得多:实测 15 条 parent_id 全是 0,而 13 条有 source,
# 其中 4 条指向同一个 fanbox 帖——那才是真正的同组信号,而且跨站可比。
+ # source 是站点转义过的 URL(`&` 代替 `&`),反转义后才是真实地址;
+ # 归组键只取 path,query 里的实体不影响既有分组的稳定性。
source = post.get("source")
+ source = html.unescape(str(source)) if source else None
parent = post.get("parent_id")
hint = origin_group_key(str(source) if source else None)
if hint is None:
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.py
index 114595ee0..b590b2774 100644
--- a/src/peach/web_follow.py
+++ b/src/peach/web_follow.py
@@ -6,6 +6,7 @@ APScheduler 任务触发。
"""
from __future__ import annotations
+import html
import json
import os
import re
@@ -64,6 +65,10 @@ def _item_tags(item) -> list[str]:
rule34.xxx 存空格分隔标签;Rule34Video 详情页存保留空格的标签列表和分类列表。
kemono 系与 f95zone 的列表接口不给标签,所以它们是空列表。
+ 实体在这里统一反转义:rule34.xxx 的 dapi 曾把 `miqo'te` 这类转义形态
+ 直接写进 metadata,归一后旧行照常显示与筛选,也和反转义后的新写法并成
+ 同一个身份。unescape 是幂等的,对已干净的标签不起作用。
+
去掉作者手柄本身:按作者筛已经有专门的筛选条,标签里再出现一次没有信息量。
"""
raw = item.metadata.get("tags")
@@ -76,7 +81,8 @@ def _item_tags(item) -> list[str]:
categories = item.metadata.get("categories")
if isinstance(categories, list):
values.extend(str(value).strip() for value in categories if str(value).strip())
- subject = str(item.metadata.get("tag") or "").casefold()
+ values = [html.unescape(value) for value in values]
+ subject = html.unescape(str(item.metadata.get("tag") or "")).casefold()
seen, tags = set(), []
for tag in values:
key = tag.casefold()
@@ -209,7 +215,9 @@ def _item_payload(item) -> dict:
"source_id": item.source_id,
"source_label": item.source_label,
"external_id": item.external_id,
- "title": item.title,
+ # 旧 rule34xxx 行的标题由带实体的标签拼成(`barnabas' mother`);
+ # 出口统一反转义,与 _item_tags 同一处理,unescape 幂等。
+ "title": html.unescape(item.title) if item.title else item.title,
"author": item.metadata.get("author") or None,
"summary": item.metadata.get("summary") or None,
"url": item.url,
diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.py
index 379d67786..5cda31ab2 100644
--- a/tests/test_follow_sources.py
+++ b/tests/test_follow_sources.py
@@ -903,6 +903,29 @@ class Rule34XxxConnectorTests(unittest.TestCase):
for noise in ("lazyprocrastinator", "video", "sound"):
self.assertNotIn(noise, first.title)
+ def test_dapi_tags_and_source_urls_are_unescaped(self):
+ """dapi 返回的标签和出处 URL 是 HTML 转义形态,入库前必须反转义。
+
+ 线上实测(2026-08-29):rule34.xxx 的 JSON 里标签写作 `miqo'te`、
+ 出处 URL 里 `&` 代替 `&`。实体原样进 metadata,页面转义后用户看到
+ 的就是 `'` 字面量(生产账本 131 行中招),同一个标签还会和反转义
+ 后的写法分裂成两个身份。归组键只取 path,query 里的实体不影响分组。
+ """
+ body = json.dumps([{
+ "id": 18534501, "image": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6.jpg",
+ "parent_id": 0,
+ "tags": "miqo'te y'shtola final_fantasy",
+ "change": 1787445400,
+ "file_url": "https://api-cdn.rule34.xxx/images/1232/miqo.jpg",
+ "source": "https://porn3dx.com/post/42957/aranea?list_type=key&sort=new",
+ }]).encode()
+ candidate = self._connector(body=body).fetch("final_fantasy").candidates[0]
+ self.assertEqual(candidate.extra["tags"], "miqo'te y'shtola final_fantasy")
+ self.assertNotIn("'", candidate.title)
+ self.assertEqual(
+ candidate.extra["source"],
+ "https://porn3dx.com/post/42957/aranea?list_type=key&sort=new")
+
def test_authentication_rejection_is_reported_as_a_credential_error(self):
connector = self._connector(
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 3a6e937e3..1925e0e9f 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -181,6 +181,27 @@ class FollowContractTests(unittest.TestCase):
self.assertNotIn("media_url", payload)
self.assertIn('"has_media"', payload)
+ def test_feed_unescapes_html_entities_in_tags_and_titles(self):
+ """关注出口的标签与标题统一反转义。
+
+ rule34.xxx 的 dapi 曾把 `miqo'te` 这类 HTML 转义形态直接写进
+ metadata,页面转义后用户看到的就是 `'` 字面量,同一个标签还会和
+ 反转义后的写法分裂成两个身份。出口归一是幂等的:旧行不修账本也能正常
+ 显示与筛选,新入库由连接器反转义,不再产生脏数据。
+ """
+ self._seed(candidates=(
+ FollowCandidate(provider="rule34xxx", external_id="18534401",
+ title="barnabas' mother · biting lip",
+ url="https://rule34.xxx/index.php?page=post&s=view&id=18534401",
+ extra={"tags": "miqo'te y'shtola barnabas'_mother"}),
+ ), provider="rule34xxx", ref="final_fantasy")
+ item = self._get()["groups"][0]["primary"]
+ self.assertEqual(item["tags"], ["miqo'te", "y'shtola", "barnabas'_mother"])
+ self.assertEqual(item["tag_types"],
+ {"miqo'te": "general", "y'shtola": "general",
+ "barnabas'_mother": "general"})
+ self.assertEqual(item["title"], "barnabas' mother · biting lip")
+
def test_external_file_pages_are_exposed_without_leaking_raw_media_urls(self):
self._seed(candidates=(FollowCandidate(
provider="f95zone", external_id="21435166", title="InitialA Collection",
@@ -1438,6 +1459,11 @@ class FollowWebSourceTests(unittest.TestCase):
["deep throat", "breast squeeze", "Final Fantasy"])
self.assertEqual(web_follow._item_tags(_Item({})), [])
self.assertEqual(web_follow._item_tags(_Item({"tags": " "})), [])
+ # rule34.xxx 旧行存的是 HTML 转义形态;出口归一后与反转义的新写法
+ # 是同一个身份,脏/净并存的重复项也合并成一个。
+ legacy = web_follow._item_tags(
+ _Item({"tags": "miqo'te y'shtola miqo'te"}))
+ self.assertEqual(legacy, ["miqo'te", "y'shtola"])
# 热门帖能带上百个标签,整串发下去会把筛选条撑爆。
many = _Item({"tags": " ".join(f"t{n}" for n in range(200))})
self.assertEqual(len(web_follow._item_tags(many)), web_follow.MAX_ITEM_TAGS)