Peach: Local-first video metadata scraper and media manager.
fix(follow): 复用封面来源白名单与原图类型判据
longmeidao2b5ef5a1baf2
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex e56fa2012..a2c31a3d9 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -2,6 +2,8 @@收藏窗口复用 BoardUI `2026.10.8` 官方技能、MIT Avatar 源码与公开 `settings-modal` 分类布局,保留 React Aria 外壳、Peach 查询、viewglide 与窄屏布局。收藏图像由 `entity_ref`、厂牌标识和本地代表作头像投影提供,不写入偏好;原始源码哈希见 `docs/BOARD_UI.md`。Rule34 视频封面使用来源缩略图,图片保留原文件扩展名;失败图片在关注数据刷新时重新尝试。无新增运行时依赖或真实 ledger 写入。+关注封面代理复用来源登记的媒体主机白名单;第三方图片地址及重定向继续执行公网 DNS 校验。+## 上游应用功能amane `0.20.0 / cc42cee6ecf290cf05af1caa347d2dc2d5aeffcd`(GPL-3.0)提供实体收藏、diff --git a/src/peach/follow_sources.py b/src/peach/follow_sources.pyindex 8ede8b972..e7b0d62ae 100644--- a/src/peach/follow_sources.py+++ b/src/peach/follow_sources.py@@ -1416,7 +1416,7 @@ class Rule34XxxConnector(_BaseConnector):@classmethoddef display_thumb_url(cls, item) -> str | None:matched = cls._PREVIEW_RE.match(str(item.thumb_url or ""))- if matched and str(item.metadata.get("media_kind") or "") == "image":+ if matched and _IMAGE_URL_RE.search(str(item.media_url or "")):return str(item.media_url or item.thumb_url or "") or Nonereturn str(item.thumb_url or "") or Nonediff --git a/src/peach/routes_media.py b/src/peach/routes_media.pyindex 6fd7fe518..cbdb9ebd5 100644--- a/src/peach/routes_media.py+++ b/src/peach/routes_media.py@@ -29,7 +29,7 @@ from fastapi.responses import (from starlette.staticfiles import StaticFilesfrom . import (- avatar_face, avatar_online, avatar_picker, avatar_provider, follow_assets, images,+ avatar_face, avatar_online, avatar_picker, avatar_provider, follow_assets, follow_providers, images,jav_poster_crop, link_marks, link_status, scraping_access, site_icons, social_links, subtitles,taste_history, timeline_sheets, web_follow,)@@ -987,7 +987,8 @@ def follow_image(request: Request, id: int, media: int | None = None,hit = cache.response(key, request)if hit is not None:return hit- target = ResolvedFollowMedia(url, item.url, public_hosts=True)+ target = ResolvedFollowMedia(url, item.url,+ allowed_hosts=follow_providers.hosts().get(item.provider, ()), public_hosts=True)if media is not None:resolved = state.follow_media_resolver.resolve(item, media)if resolved.headers:diff --git a/tests/test_fastapi_api.py b/tests/test_fastapi_api.pyindex 58b13ceb1..ee133c87b 100644--- a/tests/test_fastapi_api.py+++ b/tests/test_fastapi_api.py@@ -2158,6 +2158,34 @@ class FastApiContractTests(unittest.IsolatedAsyncioTestCase):self.app.state.http_transport.client = originalfake.close()+ async def test_follow_image_uses_registered_media_hosts_and_checks_third_party_redirects(self):+ item = SimpleNamespace(id=29, provider='rule34xxx', url='https://rule34.xxx/post/29',+ thumb_url='https://api-cdn.rule34.xxx/poster.jpg', media_url=None, metadata={}, hidden_media=())+ calls = []+ def upstream(request):+ calls.append(request.url.path)+ headers = ({'location': 'https://cdn.example/blocked.jpg'} if request.url.path == '/redirect.jpg'+ else {'content-type': 'image/jpeg'})+ return httpx.Response(302 if request.url.path == '/redirect.jpg' else 200,+ headers=headers, stream=httpx.ByteStream(b'poster'), request=request)+ original = self.app.state.http_transport.client+ fake = httpx.Client(transport=httpx.MockTransport(upstream))+ self.app.state.http_transport.client = fake+ try:+ with patch('peach.routes_media.FollowStore.item', return_value=item), \+ patch('peach.follow_stream.resolves_publicly', return_value=False):+ known = await self.client.get('/follow-image?id=29&t=secret')+ self.assertEqual(known.status_code, 200)+ self.assertEqual(known.content, b'poster')+ item.thumb_url = 'https://cdn.example/blocked.jpg'+ self.assertEqual((await self.client.get('/follow-image?id=29&t=secret')).status_code, 404)+ item.thumb_url = 'https://api-cdn.rule34.xxx/redirect.jpg'+ self.assertEqual((await self.client.get('/follow-image?id=29&t=secret')).status_code, 404)+ self.assertEqual(calls, ['/poster.jpg', '/redirect.jpg'])+ finally:+ self.app.state.http_transport.client = original+ fake.close()+async def test_follow_cover_serves_cached_frame_and_reports_retryable_failure(self):connection = sqlite3.connect(self.db)connection.executescript((ROOT / "migrations" / "0018_online_follow.sql").read_text(diff --git a/tests/test_follow_connector_base.py b/tests/test_follow_connector_base.pyindex 7cb0c6679..f0f9dd507 100644--- a/tests/test_follow_connector_base.py+++ b/tests/test_follow_connector_base.py@@ -198,9 +198,9 @@ class DisplayThumbUrlTests(unittest.TestCase):"thumbnail_" + "a" * 32 + ".jpg")image = "https://api-cdn.rule34.xxx/images/1234/" + "a" * 32 + ".png"self.assertEqual(display_thumb_url(_Item("rule34xxx", thumb_url=thumb,- media_url=image, metadata={'media_kind': 'image'})), image)+ media_url=image)), image)self.assertEqual(display_thumb_url(_Item("rule34xxx", thumb_url=thumb,- metadata={'media_kind': 'video'})), thumb)+ media_url='https://api-cdn.rule34.xxx/images/128/' + 'c' * 32 + '.mp4')), thumb)def test_a_rule34xxx_thumb_in_another_shape_is_left_alone(self):"""认不出的形状原样返回,不猜一个 bucket 出来。"""