Peach: Local-first video metadata scraper and media manager.
fix(tray): 人机验证等人点时不再弹系统通知,浏览器窗口顶到前面就是提醒
longmeidao8b7be8e9ab87
diff --git a/docs/adr/0065-cloudflare-sources-load-in-the-local-browser.md b/docs/adr/0065-cloudflare-sources-load-in-the-local-browser.mdindex 9db07386c..8fc7f12fe 100644--- a/docs/adr/0065-cloudflare-sources-load-in-the-local-browser.md+++ b/docs/adr/0065-cloudflare-sources-load-in-the-local-browser.md@@ -45,8 +45,8 @@ Cookie、User-Agent 与出口三者天然一致,不再要用户贴 Cookie;**二、验证页三态。** 导航落到验证页(标题 `Just a moment...`/`请稍候…`,页头含 `cf-chl-`、`challenge-platform`)时接着等:`AUTO_SECONDS`(40 秒)内过了就读文档,窗口不动;没过就把窗口放回屏幕内并顶到前面(先-`windowState: normal` 再给坐标,两步),同时登记到 `browser_transport.attention()`,`/healthz` 带出去,托盘每-5~10 秒探测健康时对新出现的那一条弹系统通知「<站> 的人机验证需要点一下,浏览器窗口已打开」;再等+`windowState: normal` 再给坐标,两步),同时登记到 `browser_transport.attention()`,`/healthz` 带出去供排查。+窗口顶到前面本身就是提醒,托盘不再弹系统通知:验证转圈时页上常常没有可点的框,通知只会打扰;再等`CLICK_SECONDS`(120 秒)还没过就报 `ChallengeUnsolved`,`SourceTransport` 按拒绝访问那一档冷却(`FIRST_BLOCKED_PAUSE` 起翻倍到 `blocked_pause`),措辞写「浏览器窗口再弹出时点一下验证即可」。过了或放弃都把窗口最小化收起(挪回负坐标会被系统钳住,最小化确定不占屏幕)。不用无头模式,不伪造指纹,不接解题diff --git a/frontend/src/react/scraping/scraping-page.tsx b/frontend/src/react/scraping/scraping-page.tsxindex 47d383b52..94586f26a 100644--- a/frontend/src/react/scraping/scraping-page.tsx+++ b/frontend/src/react/scraping/scraping-page.tsx@@ -170,7 +170,7 @@ function SourceCard({ source, toast }: { source: Source } & ScrapingProps) {{/* 由本机浏览器过验证的来源不收 Cookie:浏览器自己带着会话。留着「撤销 Cookie」让人清掉旧的。 */}{source.browser? <p className="text-body-2-regular text-text-secondary">- 人机验证由本机浏览器自动完成;需要点击时窗口会弹出,托盘同时提醒。这台机器上不需要 Cookie。+ 人机验证由本机浏览器自动完成;需要点击时窗口会弹出。这台机器上不需要 Cookie。</p>: null}{source.accepts_cookie && !source.browser ? <>diff --git a/src/peach/api.py b/src/peach/api.pyindex 63c7de8c3..a402fd58f 100644--- a/src/peach/api.py+++ b/src/peach/api.py@@ -453,7 +453,7 @@ def create_app("ledger_read_only_message": sync.read_only_message if read_only else None,"ledger_writer_origin": settings.review_writer_origin if read_only else None,"scheme": "https" if settings.tls_enabled else "http",- # 采集用的浏览器窗口正等着人点验证的站;托盘每次探测健康时据此提醒(ADR-0065)。+ # 采集用的浏览器窗口正等着人点验证的站,供排查时看一眼;窗口本身就是提醒,不另弹通知(ADR-0065)。"attention": browser_transport.attention(),# 健康检查可能被公网探针访问,不能在这里回传随机 Tunnel URL。"tunnel": {"enabled": settings.tunnel_enabled, "state": tunnel_state.state},diff --git a/src/peach/tray.py b/src/peach/tray.pyindex 471411de6..973149a8d 100644--- a/src/peach/tray.py+++ b/src/peach/tray.py@@ -222,8 +222,6 @@ class ServiceManager:self._last_health: dict[str, tuple[bool, str]] = {spec.name: (False, "未检测") for spec in specs}- self._seen_attention: set[str] = set()- self._pending_attention: list[str] = []self._lock = threading.RLock()def healthy(self, spec: ServiceSpec) -> bool:@@ -231,7 +229,6 @@ class ServiceManager:# HTTP 代理,httpx 默认读它(urllib.getproxies 在 macOS 走系统配置),于是# 探测 http://127.0.0.1 的请求被送进代理、由代理回 503——服务明明活着,# 状态却显示「未运行」。实测 Stash 开着时就是这样,HTTPS 探测不受影响。- attention: list = []try:response = self._health_get(spec.health_url, timeout=0.5, verify=spec.verify, trust_env=False,@@ -239,22 +236,12 @@ class ServiceManager:payload = response.json()ok = response.status_code == 200 and payload.get("ok") is Truedetail = "" if ok else f"状态码 {response.status_code}"- attention = [str(item) for item in payload.get("attention") or []]except (httpx.HTTPError, OSError, ValueError, AttributeError):ok, detail = False, "无响应"with self._lock:self._last_health[spec.name] = (ok, detail)- # 服务报的「等人点验证」按条去重:同一条只在第一次探到时提醒一次,消失后再出现算新的一条。- self._pending_attention.extend(item for item in attention if item not in self._seen_attention)- self._seen_attention = set(attention)return ok- def take_attention(self) -> list[str]:- """自上次取走之后新出现的提醒。托盘每轮探测完健康后取一次,逐条弹系统通知。"""- with self._lock:- taken, self._pending_attention = self._pending_attention, []- return taken-@propertydef log_dir(self) -> Path:return self._log_dir@@ -1082,8 +1069,6 @@ class PeachTray:self.gate.poll()for spec in self.manager.specs:self.manager.healthy(spec)- for message in self.manager.take_attention():- self.icon.notify(message, "Peach 采集")self.icon.update_menu()self.poll_build_age()@@ -1300,8 +1285,6 @@ def run_macos_menu_bar(manager: "ServiceManager", gate: "SetupGate | None" = Nongate.poll()for spec in manager.specs:manager.healthy(spec)- for message in manager.take_attention():- notify(message, "Peach 采集")def refresh_certificate() -> bool:"""本机地址变了就补签证书并重启 HTTPS。成功返回 True。diff --git a/tests/test_fastapi_api.py b/tests/test_fastapi_api.pyindex 69ac4ba79..1890f4f39 100644--- a/tests/test_fastapi_api.py+++ b/tests/test_fastapi_api.py@@ -322,7 +322,7 @@ class FastApiContractTests(unittest.IsolatedAsyncioTestCase):response = await self.client.get("/healthz")self.assertEqual(response.status_code, 200)self.assertEqual(response.json()["version"], __version__)- # 采集浏览器等人点验证的站列在这里,托盘据此提醒(ADR-0065);平时是空表。+ # 采集浏览器等人点验证的站列在这里,供排查(ADR-0065);平时是空表。self.assertEqual(response.json()["attention"], [])async def test_health_reports_the_build_commit_the_deploy_check_needs(self):diff --git a/tests/test_tray.py b/tests/test_tray.pyindex c56c0bdc8..ceb854333 100644--- a/tests/test_tray.py+++ b/tests/test_tray.py@@ -208,29 +208,6 @@ class ServiceStatusTests(unittest.TestCase):"HTTP 异常(状态码 503) · HTTPS 正常",)- def test_attention_from_the_service_is_reported_once_per_appearance(self):- """服务在 `/healthz` 里报「等人点验证」;托盘每轮探测取新出现的那几条弹通知,同一条不重复弹。"""- message = "fc2ppv-db.com 的人机验证需要点一下,浏览器窗口已打开"- payloads = iter([[message], [message], [], [message]])-- class Health:- status_code = 200-- @staticmethod- def json():- return {"ok": True, "attention": next(payloads)}-- spec = ServiceSpec("http", "http://127.0.0.1/healthz", ("noop",), True)- manager = ServiceManager((spec,), popen=Mock(), health_get=lambda *args, **kwargs: Health())- taken = []- for _ in range(4):- self.assertTrue(manager.healthy(spec))- taken.append(manager.take_attention())- self.assertEqual(taken, [[message], [], [], [message]])- plain = ServiceManager((spec,), popen=Mock(), health_get=lambda *args, **kwargs: Response())- self.assertTrue(plain.healthy(spec), "没有 attention 字段的服务照常探测")- self.assertEqual(plain.take_attention(), [])-def test_health_check_never_goes_through_a_proxy(self):"""健康检查必须绕过代理:Stash 等客户端设置系统级 HTTP 代理后,httpx 默认把 127.0.0.1 的探测送进代理、由代理回 503,服务活着却被判成「未运行」。"""diff --git a/web/dist/peach-react.js b/web/dist/peach-react.jsindex dbc38232b..3cd1bcbb2 100644--- a/web/dist/peach-react.js+++ b/web/dist/peach-react.js@@ -32227,7 +32227,7 @@ function oO({ source: e, toast: t }) {}) : null,e.browser ? /* @__PURE__ */ (0, w.jsx)("p", {className: "text-body-2-regular text-text-secondary",- children: "人机验证由本机浏览器自动完成;需要点击时窗口会弹出,托盘同时提醒。这台机器上不需要 Cookie。"+ children: "人机验证由本机浏览器自动完成;需要点击时窗口会弹出。这台机器上不需要 Cookie。"}) : null,e.accepts_cookie && !e.browser ? /* @__PURE__ */ (0, w.jsxs)(w.Fragment, { children: [/* @__PURE__ */ (0, w.jsx)("p", {