Peach: Local-first video metadata scraper and media manager.
fix(follow): add fanbox session credential
longmeidao467a52ac6907
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.mdindex 6e9d7c18f..275183c9b 100644--- a/docs/HANDOFF.md+++ b/docs/HANDOFF.md@@ -76,8 +76,10 @@ Claude 的 `.claude/settings.json` 已配置 Stop、StopFailure、SessionEnd hooF95 masked 链接与 Gofile 文件列表的凭据边界见 `f95-masked-gofile-media`;Mix 只按已解析且可播放的视频计数,不按回复数或网盘页数计数。FANBOX 多图、Gofile Bearer API、Paheal 标签页与跨站出处键见-`follow-fanbox-gofile-paheal`。Gofile token 是独立可选凭据:只进请求头,不进 URL、证据、-ledger 的公开投影或浏览器 JSON;未配置时保留分享页,但不得声称已经取得文件列表。+`follow-fanbox-gofile-paheal`。FANBOX Cookie 是本机可选凭据,只发给 FANBOX API;+Gofile token 是另一份本机可选凭据,只进 Gofile 请求头,不进 URL、证据、ledger 的公开投影+或浏览器 JSON。Gofile 当前把 contents API 限给 Premium;`error-notPremium` 要按套餐限制+报告,不能误报成 token 无效。未取得文件列表时保留分享页,不得声称已经取得视频。## 批处理边界diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 0b7589515..b42e0a032 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -21,7 +21,7 @@|---|---|---|| HTTP | 全项目共用的 `httpx.Client`/transport | 来源策略、DTO、脱敏 || RSS/Atom | `feedparser` | 有界抓取、快照、复核、导入 |-| 追更来源接口 | FANBOX 公开帖子 API、kemono 系公开 JSON API(`Accept: text/css`,站点自述的抓取路径)、rule34.xxx 官方 dapi(需账号 API key)、Paheal 标签/详情页、Gofile contents API(需账号 API token)、f95zone `latest_data.php`、线程页与站内 masked XHR | 连接器边界、凭据隔离、多媒体顺序、文件站目标校验、变体与跨站重复判定、候选复核与批准后的 online asset 投影 |+| 追更来源接口 | FANBOX 公开帖子 API、kemono 系公开 JSON API(`Accept: text/css`,站点自述的抓取路径)、rule34.xxx 官方 dapi(需账号 API key)、Paheal 标签/详情页、Gofile contents API(需 Premium 账号 API token)、f95zone `latest_data.php`、线程页与站内 masked XHR | 连接器边界、凭据隔离、多媒体顺序、文件站目标校验、变体与跨站重复判定、候选复核与批准后的 online asset 投影 || HTML 适配器 | Beautiful Soup 或 selectolax | 来源专用选择器和来源记录 || 位图 | Pillow | 头像/Logo 质量和来源策略 || 搜索 | SQLite FTS5 | 索引字段、排序、profile 感知筛选 |diff --git a/docs/STATUS.md b/docs/STATUS.mdindex 6f941643f..135b04749 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -8,7 +8,7 @@- Windows 是当前 ledger writer。启动入口为 `C:\Users\longm\Desktop\peach\peach-app\dist\Peach\Peach.exe`,代码、数据、worktree 和共享传输点都在 `C:\Users\longm\Desktop\peach\` 下;外置盘只提供 `R:\media`。- 托盘必须以普通权限启动:提升权限后的令牌看不到 CloudDrive 的 `A:` / `B:`,会把 PikPak 和 115 误报为脱盘。异常时从托盘退出,再由资源管理器或普通权限终端启动。-- Windows HTTP 为 `0.0.0.0:80`,HTTPS 为当前 LAN IPv4 的 443,mDNS 名为 `peach-win.local`。线上服务版本最后核验为 `0.7.0`、`ledger_sync=writer`。+- Windows HTTP 为 `0.0.0.0:80`,HTTPS 为当前 LAN IPv4 的 443,mDNS 名为 `peach-win.local`。线上服务版本最后核验为 `0.7.0`、`ledger_sync=writer`;`0.7.1` 已进入本次 FANBOX Cookie/Gofile Premium 修复发布流程。- macOS 是 reader,代码在 `~/Desktop/lmd.gg/peach/peach-app`,数据在相邻 `peach-data`;`peach.local` 经 8900/8443 和 pf 提供 80/443。GET 正常,写入端点返回 409。- 2026-08-27 核对 macOS:服务子进程已跑当前 `master`,但菜单栏进程仍是旧代码。托盘层改动要生效,需手动退出菜单栏项后由 `.app` 或 `launchctl kickstart -k` 重启一次。- 两端固定使用不同 mDNS 名和各自本机 CA;CA 私钥、服务器私钥和凭据不跨机同步。生成资产由 Syncthing 单向 Windows → Mac,Git 与 ledger 复制是另外两条链路。diff --git a/docs/reference-snapshots/follow-fanbox-gofile-paheal.md b/docs/reference-snapshots/follow-fanbox-gofile-paheal.mdindex 096a5ffcd..283c94156 100644--- a/docs/reference-snapshots/follow-fanbox-gofile-paheal.md+++ b/docs/reference-snapshots/follow-fanbox-gofile-paheal.md@@ -2,7 +2,7 @@- 取证日期:2026-08-28- 用途:FANBOX 多图切换、Gofile 文件页展开、Paheal 标签订阅与跨站去重。-- 凭据保护:只记录公开响应结构、状态、字节数和 SHA-256;API token 未取得、未记录。+- 凭据保护:只记录公开响应结构、状态、字节数和 SHA-256;API token 只用于现场状态验证,未记录。## FANBOX 官方帖子详情@@ -24,15 +24,24 @@ Mix 同款队列切换;正文中的文件站链接继续作为可点击资源`GET https://api.gofile.io/contents/{contentId}`,账号 API token 仅放在`Authorization: Bearer` 请求头。+官方文档在 2026-08-28 复核时明确说明:所有 API 请求都要 Bearer token,大多数 API+端点只向 Premium 账户开放;超出端点限流时返回 HTTP 429。+- 未带 token 请求 `OS2Qz9` 返回 34 字节`{"status":"error-token","data":{}}`,SHA-256`C745FF20204557E4775521417A9351E949E9BBB0B3078582649BF961FC513C61`。- 用户所说的 21 个视频在没有 token 时**未取得**,不能把分享页文字当成视频数。+- 用本机已保存的 32 字符 token 请求 `GET /accounts/getid` 返回 HTTP 200、`status=ok`,+ 证明 token 有效;同一 token 请求 `GET /contents/OS2Qz9` 返回 HTTP 401、+ `status=error-notPremium`。拒绝原因是账户套餐,不是 token 错误。Peach 新增独立的 Gofile API token 输入;配置后递归读取 API 返回的 `children`,只保留MIME 为图片或视频的文件。文件直链留在服务端 metadata,浏览器只收到媒体序号、名称、类型与缩略图;播放由 `/follow-stream` 代理,token 仍只进上游请求头。+FANBOX Cookie 是另一份本机可选凭据,只发给 `api.fanbox.cc`,用于公开 `post.info`+被验证页拦截时复用用户自己的浏览器会话;Gofile 跨站请求不会继承这份 Cookie。+## Rule34 Paheal标签页:`https://rule34.paheal.net/post/list/InitialA/1`diff --git a/docs/reference-sources.json b/docs/reference-sources.jsonindex 9901f7ed2..e45682133 100644--- a/docs/reference-sources.json+++ b/docs/reference-sources.json@@ -87,7 +87,7 @@"url": "https://lazyprocrast.fanbox.cc/posts/12228983","snapshot": "docs/reference-snapshots/follow-fanbox-gofile-paheal.md","checked_on": "2026-08-28",- "sha256": "d0de92b8a96aa504f4af06f727b2b590afd2a6b9c05756ea27f551184d0d6057",+ "sha256": "f4283802828f50f5a24a439707400325a237ad997c0720c4a9eb0b48cc90c824","role": "FANBOX 多图顺序、Gofile Bearer 文件列表、Paheal 标签订阅和出处去重证据。","consumers": ["src/peach/follow_sources.py",diff --git a/src/peach/__init__.py b/src/peach/__init__.pyindex 61ce9c18a..aa3971783 100644--- a/src/peach/__init__.py+++ b/src/peach/__init__.py@@ -1,3 +1,3 @@"""Peach application package."""-__version__ = "0.7.0"+__version__ = "0.7.1"diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.pyindex c5077a1d0..19459c019 100644--- a/src/peach/follow_sources.py+++ b/src/peach/follow_sources.py@@ -288,10 +288,13 @@ class _BaseConnector:return {"User-Agent": USER_AGENT}def _get(self, url: str, *, headers: Mapping[str, str] | None = None,- etag: str | None = None, last_modified: str | None = None) -> HttpResponse:+ etag: str | None = None, last_modified: str | None = None,+ connector_headers: bool = True) -> HttpResponse:if self.blocked_reason:raise FollowSourceError(self.blocked_reason)- merged = self._headers()+ # 跨站资源 API 不能继承来源站的 Cookie。Gofile 只拿自己的 Bearer token;+ # FANBOX/F95 的会话不得跟着资源链接发到第三方主机。+ merged = self._headers() if connector_headers else {"User-Agent": USER_AGENT}merged.update(headers or {})if etag:merged["If-None-Match"] = etag@@ -362,14 +365,24 @@ class _BaseConnector:url = f"https://api.gofile.io/contents/{urllib.parse.quote(folder)}"response = self._get(url, headers={"Accept": "application/json", "Authorization": f"Bearer {token}",- })- if response.status in (401, 403):+ }, connector_headers=False)+ payload = None+ try:+ payload = self._json(response)+ except FollowSourceError:+ # 非 JSON 的 401/403 仍按凭据拒绝处理;其他状态交给通用错误。+ pass+ api_status = payload.get("status") if isinstance(payload, dict) else None+ if api_status == "error-notPremium":+ raise FollowSourceError(+ "Gofile 文件列表 API 需要 Premium 账户;token 有效,"+ "但当前账户套餐不支持此接口")+ if response.status in (401, 403) or api_status == "error-token":raise CredentialError("Gofile 拒绝了 API token")self._check_status(response)- payload = self._json(response)+ if payload is None:+ payload = self._json(response)if not isinstance(payload, dict) or payload.get("status") != "ok":- if isinstance(payload, dict) and payload.get("status") == "error-token":- raise CredentialError("Gofile 拒绝了 API token")raise FollowSourceError("Gofile 文件列表未取得")stack = [payload.get("data")]while stack and len(items) < self.max_items:@@ -1233,6 +1246,8 @@ class FanboxConnector(_BaseConnector):"Chrome/140.0.0.0 Safari/537.36"),})+ if self.credential and self.credential.values.get("cookie"):+ headers["Cookie"] = self.credential.values["cookie"]return headersdef fetch(self, ref: str, *, etag: str | None = None,diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex 3ddbc280c..4f4692d66 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -913,13 +913,22 @@ def _existing_sources(contract):#: 每个来源要不要凭据、要哪些字段、去哪里拿。写在这里而不是模板里,因为知道#: 「rule34.xxx 缺 key 就抓不到」的是连接器边界,不是界面。CREDENTIAL_GUIDE: dict[str, dict] = {+ "fanbox": {+ "requirement": "optional",+ "fields": ["cookie"],+ # FANBOX Cookie 绑定浏览器会话与风控环境,不跨机同步。+ "syncable": [],+ "why": "公开列表不需要登录;帖子详情被 FANBOX 验证页拦住时,可用浏览器会话取得正文、多图和外部资源链接。",+ "where": "https://www.fanbox.cc/",+ "howto": "登录 FANBOX 后,从一次成功的 api.fanbox.cc/post.info 请求复制整条 Cookie 请求头。",+ },"gofile": {"requirement": "optional","fields": ["api_token"],"syncable": [],- "why": "用于展开 Gofile 文件页,取得其中的图片和视频列表;不配置仍会保留文件页链接。",+ "why": "用于展开 Gofile 文件页,取得其中的图片和视频列表;Gofile 当前要求 Premium 才能读取 contents API,不配置仍会保留文件页链接。","where": "https://gofile.io/myprofile",- "howto": "登录 Gofile 后在个人资料页复制 API token。",+ "howto": "登录 Premium Gofile 账户后,在个人资料页复制 API token。",},"kemono": {"requirement": "none"},"coomer": {"requirement": "none"},diff --git a/tests/test_follow_sources.py b/tests/test_follow_sources.pyindex 93bdcc44c..953b6b119 100644--- a/tests/test_follow_sources.py+++ b/tests/test_follow_sources.py@@ -194,6 +194,42 @@ class OfficialConnectorTests(unittest.TestCase):self.assertEqual(gofile_request.headers["Authorization"], "Bearer secret")self.assertNotIn("secret", gofile_request.url)+ def test_fanbox_cookie_stays_on_fanbox_requests(self):+ seen = []+ def route(request):+ seen.append(request)+ if "api.gofile.io" in request.url:+ return HttpResponse(200, {}, GOFILE_JSON)+ return HttpResponse(200, {}, FANBOX_DETAIL_JSON if "post.info" in request.url+ else FANBOX_JSON)+ FanboxConnector(+ transport=_routed(route),+ credential=Credential("fanbox", {"cookie": "FANBOXSESSID=session"}),+ gofile_credential=Credential("gofile", {"api_token": "secret"}),+ ).fetch("ffxivinitiala")+ fanbox_requests = [request for request in seen if "api.fanbox.cc" in request.url]+ self.assertTrue(fanbox_requests)+ self.assertTrue(all(request.headers.get("Cookie") == "FANBOXSESSID=session"+ for request in fanbox_requests))+ gofile_request = next(request for request in seen if "api.gofile.io" in request.url)+ self.assertNotIn("Cookie", gofile_request.headers)++ def test_gofile_premium_requirement_is_not_reported_as_a_bad_token(self):+ def route(request):+ if "api.gofile.io" in request.url:+ return HttpResponse(401, {"content-type": "application/json"},+ b'{"status":"error-notPremium","data":{}}')+ return HttpResponse(200, {}, FANBOX_DETAIL_JSON if "post.info" in request.url+ else FANBOX_JSON)+ connector = FanboxConnector(+ transport=_routed(route),+ gofile_credential=Credential("gofile", {"api_token": "valid-token"}),+ )+ with self.assertRaises(FollowSourceError) as caught:+ connector.fetch("ffxivinitiala")+ self.assertIn("Premium", str(caught.exception))+ self.assertIn("token 有效", str(caught.exception))+def test_one_blocked_detail_keeps_the_public_list_item(self):def route(request):if "post.info" in request.url:diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex 7312a6cea..7b6d39422 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -386,6 +386,9 @@ class FollowContractTests(unittest.TestCase):self.assertEqual(by_provider["rule34xxx"]["needs"], ["user_id", "api_key"])self.assertEqual(by_provider["rule34xxx"]["missing"], ["user_id", "api_key"])self.assertEqual(by_provider["f95zone"]["requirement"], "optional")+ self.assertEqual(by_provider["fanbox"]["requirement"], "optional")+ self.assertEqual(by_provider["fanbox"]["needs"], ["cookie"])+ self.assertTrue(by_provider["fanbox"]["path"].endswith("fanbox.json"))self.assertEqual(by_provider["gofile"]["requirement"], "optional")self.assertEqual(by_provider["gofile"]["needs"], ["api_token"])self.assertTrue(by_provider["gofile"]["path"].endswith("gofile.json"))@@ -1276,6 +1279,7 @@ class FollowWebSourceTests(unittest.TestCase):self.assertPageContains('data-cred-form=')self.assertPageContains("'/api/follow/credential'")self.assertPageContains('type="password"')+ self.assertPageContains("const fields=(row.needs||[]).map")# 值只往磁盘走:保存后清空输入框,页面上再也看不到。self.assertPageContains("form.reset();await openFollowManage(false)")self.assertPageContains("data-cred-clear")